Merge pull request #31794 from mmorel-35/modernize-pkg-1-f9be97c

chore(pkg): fix modernize linter
pull/31128/head
Terry Howe 7 months ago committed by GitHub
commit 1468449ff5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -42,7 +42,7 @@ func concatPrefix(a, b string) string {
// - Scalar values and arrays are replaced, maps are merged // - Scalar values and arrays are replaced, maps are merged
// - A chart has access to all of the variables for it, as well as all of // - A chart has access to all of the variables for it, as well as all of
// the values destined for its dependencies. // the values destined for its dependencies.
func CoalesceValues(chrt chart.Charter, vals map[string]interface{}) (common.Values, error) { func CoalesceValues(chrt chart.Charter, vals map[string]any) (common.Values, error) {
valsCopy, err := copyValues(vals) valsCopy, err := copyValues(vals)
if err != nil { if err != nil {
return vals, err return vals, err
@ -64,7 +64,7 @@ func CoalesceValues(chrt chart.Charter, vals map[string]interface{}) (common.Val
// Retaining Nils is useful when processes early in a Helm action or business // Retaining Nils is useful when processes early in a Helm action or business
// logic need to retain them for when Coalescing will happen again later in the // logic need to retain them for when Coalescing will happen again later in the
// business logic. // business logic.
func MergeValues(chrt chart.Charter, vals map[string]interface{}) (common.Values, error) { func MergeValues(chrt chart.Charter, vals map[string]any) (common.Values, error) {
valsCopy, err := copyValues(vals) valsCopy, err := copyValues(vals)
if err != nil { if err != nil {
return vals, err return vals, err
@ -72,22 +72,22 @@ func MergeValues(chrt chart.Charter, vals map[string]interface{}) (common.Values
return coalesce(log.Printf, chrt, valsCopy, "", true) return coalesce(log.Printf, chrt, valsCopy, "", true)
} }
func copyValues(vals map[string]interface{}) (common.Values, error) { func copyValues(vals map[string]any) (common.Values, error) {
v, err := copystructure.Copy(vals) v, err := copystructure.Copy(vals)
if err != nil { if err != nil {
return vals, err return vals, err
} }
valsCopy := v.(map[string]interface{}) valsCopy := v.(map[string]any)
// if we have an empty map, make sure it is initialized // if we have an empty map, make sure it is initialized
if valsCopy == nil { if valsCopy == nil {
valsCopy = make(map[string]interface{}) valsCopy = make(map[string]any)
} }
return valsCopy, nil return valsCopy, nil
} }
type printFn func(format string, v ...interface{}) type printFn func(format string, v ...any)
// coalesce coalesces the dest values and the chart values, giving priority to the dest values. // coalesce coalesces the dest values and the chart values, giving priority to the dest values.
// //
@ -96,13 +96,13 @@ type printFn func(format string, v ...interface{})
// Note, the merge argument specifies whether this is being used by MergeValues // Note, the merge argument specifies whether this is being used by MergeValues
// or CoalesceValues. Coalescing removes null values and their keys in some // or CoalesceValues. Coalescing removes null values and their keys in some
// situations while merging keeps the null values. // situations while merging keeps the null values.
func coalesce(printf printFn, ch chart.Charter, dest map[string]interface{}, prefix string, merge bool) (map[string]interface{}, error) { func coalesce(printf printFn, ch chart.Charter, dest map[string]any, prefix string, merge bool) (map[string]any, error) {
coalesceValues(printf, ch, dest, prefix, merge) coalesceValues(printf, ch, dest, prefix, merge)
return coalesceDeps(printf, ch, dest, prefix, merge) return coalesceDeps(printf, ch, dest, prefix, merge)
} }
// coalesceDeps coalesces the dependencies of the given chart. // coalesceDeps coalesces the dependencies of the given chart.
func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]interface{}, prefix string, merge bool) (map[string]interface{}, error) { func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]any, prefix string, merge bool) (map[string]any, error) {
ch, err := chart.NewAccessor(chrt) ch, err := chart.NewAccessor(chrt)
if err != nil { if err != nil {
return dest, err return dest, err
@ -114,12 +114,12 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]interface{
} }
if c, ok := dest[sub.Name()]; !ok { if c, ok := dest[sub.Name()]; !ok {
// If dest doesn't already have the key, create it. // If dest doesn't already have the key, create it.
dest[sub.Name()] = make(map[string]interface{}) dest[sub.Name()] = make(map[string]any)
} else if !istable(c) { } else if !istable(c) {
return dest, fmt.Errorf("type mismatch on %s: %t", sub.Name(), c) return dest, fmt.Errorf("type mismatch on %s: %t", sub.Name(), c)
} }
if dv, ok := dest[sub.Name()]; ok { if dv, ok := dest[sub.Name()]; ok {
dvmap := dv.(map[string]interface{}) dvmap := dv.(map[string]any)
subPrefix := concatPrefix(prefix, ch.Name()) subPrefix := concatPrefix(prefix, ch.Name())
// Get globals out of dest and merge them into dvmap. // Get globals out of dest and merge them into dvmap.
coalesceGlobals(printf, dvmap, dest, subPrefix, merge) coalesceGlobals(printf, dvmap, dest, subPrefix, merge)
@ -137,19 +137,19 @@ func coalesceDeps(printf printFn, chrt chart.Charter, dest map[string]interface{
// coalesceGlobals copies the globals out of src and merges them into dest. // coalesceGlobals copies the globals out of src and merges them into dest.
// //
// For convenience, returns dest. // For convenience, returns dest.
func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix string, _ bool) { func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) {
var dg, sg map[string]interface{} var dg, sg map[string]any
if destglob, ok := dest[common.GlobalKey]; !ok { if destglob, ok := dest[common.GlobalKey]; !ok {
dg = make(map[string]interface{}) dg = make(map[string]any)
} else if dg, ok = destglob.(map[string]interface{}); !ok { } else if dg, ok = destglob.(map[string]any); !ok {
printf("warning: skipping globals because destination %s is not a table.", common.GlobalKey) printf("warning: skipping globals because destination %s is not a table.", common.GlobalKey)
return return
} }
if srcglob, ok := src[common.GlobalKey]; !ok { if srcglob, ok := src[common.GlobalKey]; !ok {
sg = make(map[string]interface{}) sg = make(map[string]any)
} else if sg, ok = srcglob.(map[string]interface{}); !ok { } else if sg, ok = srcglob.(map[string]any); !ok {
printf("warning: skipping globals because source %s is not a table.", common.GlobalKey) printf("warning: skipping globals because source %s is not a table.", common.GlobalKey)
return return
} }
@ -160,12 +160,12 @@ func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix st
// tables in globals. // tables in globals.
for key, val := range sg { for key, val := range sg {
if istable(val) { if istable(val) {
vv := copyMap(val.(map[string]interface{})) vv := copyMap(val.(map[string]any))
if destv, ok := dg[key]; !ok { if destv, ok := dg[key]; !ok {
// Here there is no merge. We're just adding. // Here there is no merge. We're just adding.
dg[key] = vv dg[key] = vv
} else { } else {
if destvmap, ok := destv.(map[string]interface{}); !ok { if destvmap, ok := destv.(map[string]any); !ok {
printf("Conflict: cannot merge map onto non-map for %q. Skipping.", key) printf("Conflict: cannot merge map onto non-map for %q. Skipping.", key)
} else { } else {
// Basically, we reverse order of coalesce here to merge // Basically, we reverse order of coalesce here to merge
@ -189,8 +189,8 @@ func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix st
dest[common.GlobalKey] = dg dest[common.GlobalKey] = dg
} }
func copyMap(src map[string]interface{}) map[string]interface{} { func copyMap(src map[string]any) map[string]any {
m := make(map[string]interface{}, len(src)) m := make(map[string]any, len(src))
maps.Copy(m, src) maps.Copy(m, src)
return m return m
} }
@ -198,7 +198,7 @@ func copyMap(src map[string]interface{}) map[string]interface{} {
// coalesceValues builds up a values map for a particular chart. // coalesceValues builds up a values map for a particular chart.
// //
// Values in v will override the values in the chart. // Values in v will override the values in the chart.
func coalesceValues(printf printFn, c chart.Charter, v map[string]interface{}, prefix string, merge bool) { func coalesceValues(printf printFn, c chart.Charter, v map[string]any, prefix string, merge bool) {
ch, err := chart.NewAccessor(c) ch, err := chart.NewAccessor(c)
if err != nil { if err != nil {
return return
@ -210,7 +210,7 @@ func coalesceValues(printf printFn, c chart.Charter, v map[string]interface{}, p
// the original c.Values is altered. Creating a deep copy stops the problem. // the original c.Values is altered. Creating a deep copy stops the problem.
// This section is fault-tolerant as there is no ability to return an error. // This section is fault-tolerant as there is no ability to return an error.
valuesCopy, err := copystructure.Copy(ch.Values()) valuesCopy, err := copystructure.Copy(ch.Values())
var vc map[string]interface{} var vc map[string]any
var ok bool var ok bool
if err != nil { if err != nil {
// If there is an error something is wrong with copying c.Values it // If there is an error something is wrong with copying c.Values it
@ -220,7 +220,7 @@ func coalesceValues(printf printFn, c chart.Charter, v map[string]interface{}, p
printf("warning: unable to copy values, err: %s", err) printf("warning: unable to copy values, err: %s", err)
vc = ch.Values() vc = ch.Values()
} else { } else {
vc, ok = valuesCopy.(map[string]interface{}) vc, ok = valuesCopy.(map[string]any)
if !ok { if !ok {
// c.Values has a map[string]interface{} structure. If the copy of // c.Values has a map[string]interface{} structure. If the copy of
// it cannot be treated as map[string]interface{} there is something // it cannot be treated as map[string]interface{} there is something
@ -238,9 +238,9 @@ func coalesceValues(printf printFn, c chart.Charter, v map[string]interface{}, p
// This allows Helm's various sources of values (value files or --set) to // This allows Helm's various sources of values (value files or --set) to
// remove incompatible keys from any previous chart, file, or set values. // remove incompatible keys from any previous chart, file, or set values.
delete(v, key) delete(v, key)
} else if dest, ok := value.(map[string]interface{}); ok { } else if dest, ok := value.(map[string]any); ok {
// if v[key] is a table, merge nv's val table into v[key]. // if v[key] is a table, merge nv's val table into v[key].
src, ok := val.(map[string]interface{}) src, ok := val.(map[string]any)
if !ok { if !ok {
// If the original value is nil, there is nothing to coalesce, so we don't print // If the original value is nil, there is nothing to coalesce, so we don't print
// the warning // the warning
@ -283,18 +283,18 @@ func childChartMergeTrue(chrt chart.Charter, key string, merge bool) bool {
// CoalesceTables merges a source map into a destination map. // CoalesceTables merges a source map into a destination map.
// //
// dest is considered authoritative. // dest is considered authoritative.
func CoalesceTables(dst, src map[string]interface{}) map[string]interface{} { func CoalesceTables(dst, src map[string]any) map[string]any {
return coalesceTablesFullKey(log.Printf, dst, src, "", false) return coalesceTablesFullKey(log.Printf, dst, src, "", false)
} }
func MergeTables(dst, src map[string]interface{}) map[string]interface{} { func MergeTables(dst, src map[string]any) map[string]any {
return coalesceTablesFullKey(log.Printf, dst, src, "", true) return coalesceTablesFullKey(log.Printf, dst, src, "", true)
} }
// coalesceTablesFullKey merges a source map into a destination map. // coalesceTablesFullKey merges a source map into a destination map.
// //
// dest is considered authoritative. // dest is considered authoritative.
func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, prefix string, merge bool) map[string]interface{} { func coalesceTablesFullKey(printf printFn, dst, src map[string]any, prefix string, merge bool) map[string]any {
// When --reuse-values is set but there are no modifications yet, return new values // When --reuse-values is set but there are no modifications yet, return new values
if src == nil { if src == nil {
return dst return dst
@ -330,7 +330,7 @@ func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, pref
dst[key] = val dst[key] = val
} else if istable(val) { } else if istable(val) {
if istable(dv) { if istable(dv) {
coalesceTablesFullKey(printf, dv.(map[string]interface{}), val.(map[string]interface{}), fullkey, merge) coalesceTablesFullKey(printf, dv.(map[string]any), val.(map[string]any), fullkey, merge)
} else { } else {
printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val) printf("warning: cannot overwrite table with non table for %s (%v)", fullkey, val)
} }
@ -342,7 +342,7 @@ func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, pref
} }
// istable is a special-purpose function to see if the present thing matches the definition of a YAML table. // istable is a special-purpose function to see if the present thing matches the definition of a YAML table.
func istable(v interface{}) bool { func istable(v any) bool {
_, ok := v.(map[string]interface{}) _, ok := v.(map[string]any)
return ok return ok
} }

@ -75,65 +75,65 @@ func TestCoalesceValues(t *testing.T) {
c := withDeps(&chart.Chart{ c := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "moby"}, Metadata: &chart.Metadata{Name: "moby"},
Values: map[string]interface{}{ Values: map[string]any{
"back": "exists", "back": "exists",
"bottom": "exists", "bottom": "exists",
"front": "exists", "front": "exists",
"left": "exists", "left": "exists",
"name": "moby", "name": "moby",
"nested": map[string]interface{}{"boat": true}, "nested": map[string]any{"boat": true},
"override": "bad", "override": "bad",
"right": "exists", "right": "exists",
"scope": "moby", "scope": "moby",
"top": "nope", "top": "nope",
"global": map[string]interface{}{ "global": map[string]any{
"nested2": map[string]interface{}{"l0": "moby"}, "nested2": map[string]any{"l0": "moby"},
}, },
"pequod": map[string]interface{}{ "pequod": map[string]any{
"boat": "maybe", "boat": "maybe",
"ahab": map[string]interface{}{ "ahab": map[string]any{
"boat": "maybe", "boat": "maybe",
"nested": map[string]interface{}{"boat": "maybe"}, "nested": map[string]any{"boat": "maybe"},
}, },
}, },
}, },
}, },
withDeps(&chart.Chart{ withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "pequod"}, Metadata: &chart.Metadata{Name: "pequod"},
Values: map[string]interface{}{ Values: map[string]any{
"name": "pequod", "name": "pequod",
"scope": "pequod", "scope": "pequod",
"global": map[string]interface{}{ "global": map[string]any{
"nested2": map[string]interface{}{"l1": "pequod"}, "nested2": map[string]any{"l1": "pequod"},
}, },
"boat": false, "boat": false,
"ahab": map[string]interface{}{ "ahab": map[string]any{
"boat": false, "boat": false,
"nested": map[string]interface{}{"boat": false}, "nested": map[string]any{"boat": false},
}, },
}, },
}, },
&chart.Chart{ &chart.Chart{
Metadata: &chart.Metadata{Name: "ahab"}, Metadata: &chart.Metadata{Name: "ahab"},
Values: map[string]interface{}{ Values: map[string]any{
"global": map[string]interface{}{ "global": map[string]any{
"nested": map[string]interface{}{"foo": "bar", "foo2": "bar2"}, "nested": map[string]any{"foo": "bar", "foo2": "bar2"},
"nested2": map[string]interface{}{"l2": "ahab"}, "nested2": map[string]any{"l2": "ahab"},
}, },
"scope": "ahab", "scope": "ahab",
"name": "ahab", "name": "ahab",
"boat": true, "boat": true,
"nested": map[string]interface{}{"foo": false, "boat": true}, "nested": map[string]any{"foo": false, "boat": true},
"object": map[string]interface{}{"foo": "bar"}, "object": map[string]any{"foo": "bar"},
}, },
}, },
), ),
&chart.Chart{ &chart.Chart{
Metadata: &chart.Metadata{Name: "spouter"}, Metadata: &chart.Metadata{Name: "spouter"},
Values: map[string]interface{}{ Values: map[string]any{
"scope": "spouter", "scope": "spouter",
"global": map[string]interface{}{ "global": map[string]any{
"nested2": map[string]interface{}{"l1": "spouter"}, "nested2": map[string]any{"l1": "spouter"},
}, },
}, },
}, },
@ -215,21 +215,21 @@ func TestCoalesceValues(t *testing.T) {
} }
} }
if _, ok := v["nested"].(map[string]interface{})["boat"]; ok { if _, ok := v["nested"].(map[string]any)["boat"]; ok {
t.Error("Expected nested boat key to be removed, still present") t.Error("Expected nested boat key to be removed, still present")
} }
subchart := v["pequod"].(map[string]interface{}) subchart := v["pequod"].(map[string]any)
if _, ok := subchart["boat"]; ok { if _, ok := subchart["boat"]; ok {
t.Error("Expected subchart boat key to be removed, still present") t.Error("Expected subchart boat key to be removed, still present")
} }
subsubchart := subchart["ahab"].(map[string]interface{}) subsubchart := subchart["ahab"].(map[string]any)
if _, ok := subsubchart["boat"]; ok { if _, ok := subsubchart["boat"]; ok {
t.Error("Expected sub-subchart ahab boat key to be removed, still present") t.Error("Expected sub-subchart ahab boat key to be removed, still present")
} }
if _, ok := subsubchart["nested"].(map[string]interface{})["boat"]; ok { if _, ok := subsubchart["nested"].(map[string]any)["boat"]; ok {
t.Error("Expected sub-subchart nested boat key to be removed, still present") t.Error("Expected sub-subchart nested boat key to be removed, still present")
} }
@ -241,7 +241,7 @@ func TestCoalesceValues(t *testing.T) {
is.Equal(valsCopy, vals) is.Equal(valsCopy, vals)
} }
func ttpl(tpl string, v map[string]interface{}) (string, error) { func ttpl(tpl string, v map[string]any) (string, error) {
var b bytes.Buffer var b bytes.Buffer
tt := template.Must(template.New("t").Parse(tpl)) tt := template.Must(template.New("t").Parse(tpl))
err := tt.Execute(&b, v) err := tt.Execute(&b, v)
@ -253,52 +253,52 @@ func TestMergeValues(t *testing.T) {
c := withDeps(&chart.Chart{ c := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "moby"}, Metadata: &chart.Metadata{Name: "moby"},
Values: map[string]interface{}{ Values: map[string]any{
"back": "exists", "back": "exists",
"bottom": "exists", "bottom": "exists",
"front": "exists", "front": "exists",
"left": "exists", "left": "exists",
"name": "moby", "name": "moby",
"nested": map[string]interface{}{"boat": true}, "nested": map[string]any{"boat": true},
"override": "bad", "override": "bad",
"right": "exists", "right": "exists",
"scope": "moby", "scope": "moby",
"top": "nope", "top": "nope",
"global": map[string]interface{}{ "global": map[string]any{
"nested2": map[string]interface{}{"l0": "moby"}, "nested2": map[string]any{"l0": "moby"},
}, },
}, },
}, },
withDeps(&chart.Chart{ withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "pequod"}, Metadata: &chart.Metadata{Name: "pequod"},
Values: map[string]interface{}{ Values: map[string]any{
"name": "pequod", "name": "pequod",
"scope": "pequod", "scope": "pequod",
"global": map[string]interface{}{ "global": map[string]any{
"nested2": map[string]interface{}{"l1": "pequod"}, "nested2": map[string]any{"l1": "pequod"},
}, },
}, },
}, },
&chart.Chart{ &chart.Chart{
Metadata: &chart.Metadata{Name: "ahab"}, Metadata: &chart.Metadata{Name: "ahab"},
Values: map[string]interface{}{ Values: map[string]any{
"global": map[string]interface{}{ "global": map[string]any{
"nested": map[string]interface{}{"foo": "bar"}, "nested": map[string]any{"foo": "bar"},
"nested2": map[string]interface{}{"l2": "ahab"}, "nested2": map[string]any{"l2": "ahab"},
}, },
"scope": "ahab", "scope": "ahab",
"name": "ahab", "name": "ahab",
"boat": true, "boat": true,
"nested": map[string]interface{}{"foo": false, "bar": true}, "nested": map[string]any{"foo": false, "bar": true},
}, },
}, },
), ),
&chart.Chart{ &chart.Chart{
Metadata: &chart.Metadata{Name: "spouter"}, Metadata: &chart.Metadata{Name: "spouter"},
Values: map[string]interface{}{ Values: map[string]any{
"scope": "spouter", "scope": "spouter",
"global": map[string]interface{}{ "global": map[string]any{
"nested2": map[string]interface{}{"l1": "spouter"}, "nested2": map[string]any{"l1": "spouter"},
}, },
}, },
}, },
@ -383,16 +383,16 @@ func TestMergeValues(t *testing.T) {
} }
} }
if _, ok := v["nested"].(map[string]interface{})["boat"]; !ok { if _, ok := v["nested"].(map[string]any)["boat"]; !ok {
t.Error("Expected nested boat key to be present but it was removed") t.Error("Expected nested boat key to be present but it was removed")
} }
subchart := v["pequod"].(map[string]interface{})["ahab"].(map[string]interface{}) subchart := v["pequod"].(map[string]any)["ahab"].(map[string]any)
if _, ok := subchart["boat"]; !ok { if _, ok := subchart["boat"]; !ok {
t.Error("Expected subchart boat key to be present but it was removed") t.Error("Expected subchart boat key to be present but it was removed")
} }
if _, ok := subchart["nested"].(map[string]interface{})["bar"]; !ok { if _, ok := subchart["nested"].(map[string]any)["bar"]; !ok {
t.Error("Expected subchart nested bar key to be present but it was removed") t.Error("Expected subchart nested bar key to be present but it was removed")
} }
@ -401,28 +401,28 @@ func TestMergeValues(t *testing.T) {
} }
func TestCoalesceTables(t *testing.T) { func TestCoalesceTables(t *testing.T) {
dst := map[string]interface{}{ dst := map[string]any{
"name": "Ishmael", "name": "Ishmael",
"address": map[string]interface{}{ "address": map[string]any{
"street": "123 Spouter Inn Ct.", "street": "123 Spouter Inn Ct.",
"city": "Nantucket", "city": "Nantucket",
"country": nil, "country": nil,
}, },
"details": map[string]interface{}{ "details": map[string]any{
"friends": []string{"Tashtego"}, "friends": []string{"Tashtego"},
}, },
"boat": "pequod", "boat": "pequod",
"hole": nil, "hole": nil,
} }
src := map[string]interface{}{ src := map[string]any{
"occupation": "whaler", "occupation": "whaler",
"address": map[string]interface{}{ "address": map[string]any{
"state": "MA", "state": "MA",
"street": "234 Spouter Inn Ct.", "street": "234 Spouter Inn Ct.",
"country": "US", "country": "US",
}, },
"details": "empty", "details": "empty",
"boat": map[string]interface{}{ "boat": map[string]any{
"mast": true, "mast": true,
}, },
"hole": "black", "hole": "black",
@ -439,7 +439,7 @@ func TestCoalesceTables(t *testing.T) {
t.Errorf("Unexpected occupation: %s", dst["occupation"]) t.Errorf("Unexpected occupation: %s", dst["occupation"])
} }
addr, ok := dst["address"].(map[string]interface{}) addr, ok := dst["address"].(map[string]any)
if !ok { if !ok {
t.Fatal("Address went away.") t.Fatal("Address went away.")
} }
@ -460,7 +460,7 @@ func TestCoalesceTables(t *testing.T) {
t.Error("The country is not left out.") t.Error("The country is not left out.")
} }
if det, ok := dst["details"].(map[string]interface{}); !ok { if det, ok := dst["details"].(map[string]any); !ok {
t.Fatalf("Details is the wrong type: %v", dst["details"]) t.Fatalf("Details is the wrong type: %v", dst["details"])
} else if _, ok := det["friends"]; !ok { } else if _, ok := det["friends"]; !ok {
t.Error("Could not find your friends. Maybe you don't have any. :-(") t.Error("Could not find your friends. Maybe you don't have any. :-(")
@ -474,14 +474,14 @@ func TestCoalesceTables(t *testing.T) {
t.Error("The hole still exists.") t.Error("The hole still exists.")
} }
dst2 := map[string]interface{}{ dst2 := map[string]any{
"name": "Ishmael", "name": "Ishmael",
"address": map[string]interface{}{ "address": map[string]any{
"street": "123 Spouter Inn Ct.", "street": "123 Spouter Inn Ct.",
"city": "Nantucket", "city": "Nantucket",
"country": "US", "country": "US",
}, },
"details": map[string]interface{}{ "details": map[string]any{
"friends": []string{"Tashtego"}, "friends": []string{"Tashtego"},
}, },
"boat": "pequod", "boat": "pequod",
@ -496,7 +496,7 @@ func TestCoalesceTables(t *testing.T) {
t.Errorf("Unexpected name: %s", dst2["name"]) t.Errorf("Unexpected name: %s", dst2["name"])
} }
addr2, ok := dst2["address"].(map[string]interface{}) addr2, ok := dst2["address"].(map[string]any)
if !ok { if !ok {
t.Fatal("Address went away.") t.Fatal("Address went away.")
} }
@ -513,7 +513,7 @@ func TestCoalesceTables(t *testing.T) {
t.Errorf("Unexpected Country: %v", addr2["country"]) t.Errorf("Unexpected Country: %v", addr2["country"])
} }
if det2, ok := dst2["details"].(map[string]interface{}); !ok { if det2, ok := dst2["details"].(map[string]any); !ok {
t.Fatalf("Details is the wrong type: %v", dst2["details"]) t.Fatalf("Details is the wrong type: %v", dst2["details"])
} else if _, ok := det2["friends"]; !ok { } else if _, ok := det2["friends"]; !ok {
t.Error("Could not find your friends. Maybe you don't have any. :-(") t.Error("Could not find your friends. Maybe you don't have any. :-(")
@ -529,28 +529,28 @@ func TestCoalesceTables(t *testing.T) {
} }
func TestMergeTables(t *testing.T) { func TestMergeTables(t *testing.T) {
dst := map[string]interface{}{ dst := map[string]any{
"name": "Ishmael", "name": "Ishmael",
"address": map[string]interface{}{ "address": map[string]any{
"street": "123 Spouter Inn Ct.", "street": "123 Spouter Inn Ct.",
"city": "Nantucket", "city": "Nantucket",
"country": nil, "country": nil,
}, },
"details": map[string]interface{}{ "details": map[string]any{
"friends": []string{"Tashtego"}, "friends": []string{"Tashtego"},
}, },
"boat": "pequod", "boat": "pequod",
"hole": nil, "hole": nil,
} }
src := map[string]interface{}{ src := map[string]any{
"occupation": "whaler", "occupation": "whaler",
"address": map[string]interface{}{ "address": map[string]any{
"state": "MA", "state": "MA",
"street": "234 Spouter Inn Ct.", "street": "234 Spouter Inn Ct.",
"country": "US", "country": "US",
}, },
"details": "empty", "details": "empty",
"boat": map[string]interface{}{ "boat": map[string]any{
"mast": true, "mast": true,
}, },
"hole": "black", "hole": "black",
@ -567,7 +567,7 @@ func TestMergeTables(t *testing.T) {
t.Errorf("Unexpected occupation: %s", dst["occupation"]) t.Errorf("Unexpected occupation: %s", dst["occupation"])
} }
addr, ok := dst["address"].(map[string]interface{}) addr, ok := dst["address"].(map[string]any)
if !ok { if !ok {
t.Fatal("Address went away.") t.Fatal("Address went away.")
} }
@ -590,7 +590,7 @@ func TestMergeTables(t *testing.T) {
t.Error("The country is left out.") t.Error("The country is left out.")
} }
if det, ok := dst["details"].(map[string]interface{}); !ok { if det, ok := dst["details"].(map[string]any); !ok {
t.Fatalf("Details is the wrong type: %v", dst["details"]) t.Fatalf("Details is the wrong type: %v", dst["details"])
} else if _, ok := det["friends"]; !ok { } else if _, ok := det["friends"]; !ok {
t.Error("Could not find your friends. Maybe you don't have any. :-(") t.Error("Could not find your friends. Maybe you don't have any. :-(")
@ -606,14 +606,14 @@ func TestMergeTables(t *testing.T) {
t.Error("The hole no longer exists.") t.Error("The hole no longer exists.")
} }
dst2 := map[string]interface{}{ dst2 := map[string]any{
"name": "Ishmael", "name": "Ishmael",
"address": map[string]interface{}{ "address": map[string]any{
"street": "123 Spouter Inn Ct.", "street": "123 Spouter Inn Ct.",
"city": "Nantucket", "city": "Nantucket",
"country": "US", "country": "US",
}, },
"details": map[string]interface{}{ "details": map[string]any{
"friends": []string{"Tashtego"}, "friends": []string{"Tashtego"},
}, },
"boat": "pequod", "boat": "pequod",
@ -629,7 +629,7 @@ func TestMergeTables(t *testing.T) {
t.Errorf("Unexpected name: %s", dst2["name"]) t.Errorf("Unexpected name: %s", dst2["name"])
} }
addr2, ok := dst2["address"].(map[string]interface{}) addr2, ok := dst2["address"].(map[string]any)
if !ok { if !ok {
t.Fatal("Address went away.") t.Fatal("Address went away.")
} }
@ -646,7 +646,7 @@ func TestMergeTables(t *testing.T) {
t.Errorf("Unexpected Country: %v", addr2["country"]) t.Errorf("Unexpected Country: %v", addr2["country"])
} }
if det2, ok := dst2["details"].(map[string]interface{}); !ok { if det2, ok := dst2["details"].(map[string]any); !ok {
t.Fatalf("Details is the wrong type: %v", dst2["details"]) t.Fatalf("Details is the wrong type: %v", dst2["details"])
} else if _, ok := det2["friends"]; !ok { } else if _, ok := det2["friends"]; !ok {
t.Error("Could not find your friends. Maybe you don't have any. :-(") t.Error("Could not find your friends. Maybe you don't have any. :-(")
@ -669,24 +669,24 @@ func TestCoalesceValuesWarnings(t *testing.T) {
c := withDeps(&chart.Chart{ c := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "level1"}, Metadata: &chart.Metadata{Name: "level1"},
Values: map[string]interface{}{ Values: map[string]any{
"name": "moby", "name": "moby",
}, },
}, },
withDeps(&chart.Chart{ withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "level2"}, Metadata: &chart.Metadata{Name: "level2"},
Values: map[string]interface{}{ Values: map[string]any{
"name": "pequod", "name": "pequod",
}, },
}, },
&chart.Chart{ &chart.Chart{
Metadata: &chart.Metadata{Name: "level3"}, Metadata: &chart.Metadata{Name: "level3"},
Values: map[string]interface{}{ Values: map[string]any{
"name": "ahab", "name": "ahab",
"boat": true, "boat": true,
"spear": map[string]interface{}{ "spear": map[string]any{
"tip": true, "tip": true,
"sail": map[string]interface{}{ "sail": map[string]any{
"cotton": true, "cotton": true,
}, },
}, },
@ -695,12 +695,12 @@ func TestCoalesceValuesWarnings(t *testing.T) {
), ),
) )
vals := map[string]interface{}{ vals := map[string]any{
"level2": map[string]interface{}{ "level2": map[string]any{
"level3": map[string]interface{}{ "level3": map[string]any{
"boat": map[string]interface{}{"mast": true}, "boat": map[string]any{"mast": true},
"spear": map[string]interface{}{ "spear": map[string]any{
"tip": map[string]interface{}{ "tip": map[string]any{
"sharp": true, "sharp": true,
}, },
"sail": true, "sail": true,
@ -710,7 +710,7 @@ func TestCoalesceValuesWarnings(t *testing.T) {
} }
warnings := make([]string, 0) warnings := make([]string, 0)
printf := func(format string, v ...interface{}) { printf := func(format string, v ...any) {
t.Logf(format, v...) t.Logf(format, v...)
warnings = append(warnings, fmt.Sprintf(format, v...)) warnings = append(warnings, fmt.Sprintf(format, v...))
} }

@ -669,7 +669,7 @@ func CreateFrom(chartfile *chart.Metadata, dest, src string) error {
return fmt.Errorf("reading values file: %w", err) return fmt.Errorf("reading values file: %w", err)
} }
var m map[string]interface{} var m map[string]any
if err := yaml.Unmarshal(transform(string(b), schart.Name()), &m); err != nil { if err := yaml.Unmarshal(transform(string(b), schart.Name()), &m); err != nil {
return fmt.Errorf("transforming values file: %w", err) return fmt.Errorf("transforming values file: %w", err)
} }

@ -26,7 +26,7 @@ import (
func TestParseLiteral(t *testing.T) { func TestParseLiteral(t *testing.T) {
cases := []struct { cases := []struct {
str string str string
expect map[string]interface{} expect map[string]any
err bool err bool
}{ }{
{ {
@ -35,61 +35,61 @@ func TestParseLiteral(t *testing.T) {
}, },
{ {
str: "name=", str: "name=",
expect: map[string]interface{}{"name": ""}, expect: map[string]any{"name": ""},
}, },
{ {
str: "name=value", str: "name=value",
expect: map[string]interface{}{"name": "value"}, expect: map[string]any{"name": "value"},
err: false, err: false,
}, },
{ {
str: "long_int_string=1234567890", str: "long_int_string=1234567890",
expect: map[string]interface{}{"long_int_string": "1234567890"}, expect: map[string]any{"long_int_string": "1234567890"},
err: false, err: false,
}, },
{ {
str: "boolean=true", str: "boolean=true",
expect: map[string]interface{}{"boolean": "true"}, expect: map[string]any{"boolean": "true"},
err: false, err: false,
}, },
{ {
str: "is_null=null", str: "is_null=null",
expect: map[string]interface{}{"is_null": "null"}, expect: map[string]any{"is_null": "null"},
err: false, err: false,
}, },
{ {
str: "zero=0", str: "zero=0",
expect: map[string]interface{}{"zero": "0"}, expect: map[string]any{"zero": "0"},
err: false, err: false,
}, },
{ {
str: "name1=null,name2=value2", str: "name1=null,name2=value2",
expect: map[string]interface{}{"name1": "null,name2=value2"}, expect: map[string]any{"name1": "null,name2=value2"},
err: false, err: false,
}, },
{ {
str: "name1=value,,,tail", str: "name1=value,,,tail",
expect: map[string]interface{}{"name1": "value,,,tail"}, expect: map[string]any{"name1": "value,,,tail"},
err: false, err: false,
}, },
{ {
str: "leading_zeros=00009", str: "leading_zeros=00009",
expect: map[string]interface{}{"leading_zeros": "00009"}, expect: map[string]any{"leading_zeros": "00009"},
err: false, err: false,
}, },
{ {
str: "name=one two three", str: "name=one two three",
expect: map[string]interface{}{"name": "one two three"}, expect: map[string]any{"name": "one two three"},
err: false, err: false,
}, },
{ {
str: "outer.inner=value", str: "outer.inner=value",
expect: map[string]interface{}{"outer": map[string]interface{}{"inner": "value"}}, expect: map[string]any{"outer": map[string]any{"inner": "value"}},
err: false, err: false,
}, },
{ {
str: "outer.middle.inner=value", str: "outer.middle.inner=value",
expect: map[string]interface{}{"outer": map[string]interface{}{"middle": map[string]interface{}{"inner": "value"}}}, expect: map[string]any{"outer": map[string]any{"middle": map[string]any{"inner": "value"}}},
err: false, err: false,
}, },
{ {
@ -98,7 +98,7 @@ func TestParseLiteral(t *testing.T) {
}, },
{ {
str: "name1.name2=", str: "name1.name2=",
expect: map[string]interface{}{"name1": map[string]interface{}{"name2": ""}}, expect: map[string]any{"name1": map[string]any{"name2": ""}},
err: false, err: false,
}, },
{ {
@ -111,20 +111,20 @@ func TestParseLiteral(t *testing.T) {
}, },
{ {
str: "name1={value1,value2}", str: "name1={value1,value2}",
expect: map[string]interface{}{"name1": "{value1,value2}"}, expect: map[string]any{"name1": "{value1,value2}"},
}, },
// List support // List support
{ {
str: "list[0]=foo", str: "list[0]=foo",
expect: map[string]interface{}{"list": []string{"foo"}}, expect: map[string]any{"list": []string{"foo"}},
err: false, err: false,
}, },
{ {
str: "list[0].foo=bar", str: "list[0].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"list": []interface{}{ "list": []any{
map[string]interface{}{"foo": "bar"}, map[string]any{"foo": "bar"},
}, },
}, },
err: false, err: false,
@ -135,7 +135,7 @@ func TestParseLiteral(t *testing.T) {
}, },
{ {
str: "list[3]=bar", str: "list[3]=bar",
expect: map[string]interface{}{"list": []interface{}{nil, nil, nil, "bar"}}, expect: map[string]any{"list": []any{nil, nil, nil, "bar"}},
err: false, err: false,
}, },
{ {
@ -144,133 +144,133 @@ func TestParseLiteral(t *testing.T) {
}, },
{ {
str: "noval[0]", str: "noval[0]",
expect: map[string]interface{}{"noval": []interface{}{}}, expect: map[string]any{"noval": []any{}},
err: false, err: false,
}, },
{ {
str: "noval[0]=", str: "noval[0]=",
expect: map[string]interface{}{"noval": []interface{}{""}}, expect: map[string]any{"noval": []any{""}},
err: false, err: false,
}, },
{ {
str: "nested[0][0]=1", str: "nested[0][0]=1",
expect: map[string]interface{}{"nested": []interface{}{[]interface{}{"1"}}}, expect: map[string]any{"nested": []any{[]any{"1"}}},
err: false, err: false,
}, },
{ {
str: "nested[1][1]=1", str: "nested[1][1]=1",
expect: map[string]interface{}{"nested": []interface{}{nil, []interface{}{nil, "1"}}}, expect: map[string]any{"nested": []any{nil, []any{nil, "1"}}},
err: false, err: false,
}, },
{ {
str: "name1.name2[0].foo=bar", str: "name1.name2[0].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"name1": map[string]interface{}{ "name1": map[string]any{
"name2": []map[string]interface{}{{"foo": "bar"}}, "name2": []map[string]any{{"foo": "bar"}},
}, },
}, },
}, },
{ {
str: "name1.name2[1].foo=bar", str: "name1.name2[1].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"name1": map[string]interface{}{ "name1": map[string]any{
"name2": []map[string]interface{}{nil, {"foo": "bar"}}, "name2": []map[string]any{nil, {"foo": "bar"}},
}, },
}, },
}, },
{ {
str: "name1.name2[1].foo=bar", str: "name1.name2[1].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"name1": map[string]interface{}{ "name1": map[string]any{
"name2": []map[string]interface{}{nil, {"foo": "bar"}}, "name2": []map[string]any{nil, {"foo": "bar"}},
}, },
}, },
}, },
{ {
str: "]={}].", str: "]={}].",
expect: map[string]interface{}{"]": "{}]."}, expect: map[string]any{"]": "{}]."},
err: false, err: false,
}, },
// issue test cases: , = $ ( ) { } . \ \\ // issue test cases: , = $ ( ) { } . \ \\
{ {
str: "name=val,val", str: "name=val,val",
expect: map[string]interface{}{"name": "val,val"}, expect: map[string]any{"name": "val,val"},
err: false, err: false,
}, },
{ {
str: "name=val.val", str: "name=val.val",
expect: map[string]interface{}{"name": "val.val"}, expect: map[string]any{"name": "val.val"},
err: false, err: false,
}, },
{ {
str: "name=val=val", str: "name=val=val",
expect: map[string]interface{}{"name": "val=val"}, expect: map[string]any{"name": "val=val"},
err: false, err: false,
}, },
{ {
str: "name=val$val", str: "name=val$val",
expect: map[string]interface{}{"name": "val$val"}, expect: map[string]any{"name": "val$val"},
err: false, err: false,
}, },
{ {
str: "name=(value", str: "name=(value",
expect: map[string]interface{}{"name": "(value"}, expect: map[string]any{"name": "(value"},
err: false, err: false,
}, },
{ {
str: "name=value)", str: "name=value)",
expect: map[string]interface{}{"name": "value)"}, expect: map[string]any{"name": "value)"},
err: false, err: false,
}, },
{ {
str: "name=(value)", str: "name=(value)",
expect: map[string]interface{}{"name": "(value)"}, expect: map[string]any{"name": "(value)"},
err: false, err: false,
}, },
{ {
str: "name={value", str: "name={value",
expect: map[string]interface{}{"name": "{value"}, expect: map[string]any{"name": "{value"},
err: false, err: false,
}, },
{ {
str: "name=value}", str: "name=value}",
expect: map[string]interface{}{"name": "value}"}, expect: map[string]any{"name": "value}"},
err: false, err: false,
}, },
{ {
str: "name={value}", str: "name={value}",
expect: map[string]interface{}{"name": "{value}"}, expect: map[string]any{"name": "{value}"},
err: false, err: false,
}, },
{ {
str: "name={value1,value2}", str: "name={value1,value2}",
expect: map[string]interface{}{"name": "{value1,value2}"}, expect: map[string]any{"name": "{value1,value2}"},
err: false, err: false,
}, },
{ {
str: `name=val\val`, str: `name=val\val`,
expect: map[string]interface{}{"name": `val\val`}, expect: map[string]any{"name": `val\val`},
err: false, err: false,
}, },
{ {
str: `name=val\\val`, str: `name=val\\val`,
expect: map[string]interface{}{"name": `val\\val`}, expect: map[string]any{"name": `val\\val`},
err: false, err: false,
}, },
{ {
str: `name=val\\\val`, str: `name=val\\\val`,
expect: map[string]interface{}{"name": `val\\\val`}, expect: map[string]any{"name": `val\\\val`},
err: false, err: false,
}, },
{ {
str: `name={val,.?*v\0a!l)some`, str: `name={val,.?*v\0a!l)some`,
expect: map[string]interface{}{"name": `{val,.?*v\0a!l)some`}, expect: map[string]any{"name": `{val,.?*v\0a!l)some`},
err: false, err: false,
}, },
{ {
str: `name=em%GT)tqUDqz,i-\h+Mbqs-!:.m\\rE=mkbM#rR}@{-k@`, str: `name=em%GT)tqUDqz,i-\h+Mbqs-!:.m\\rE=mkbM#rR}@{-k@`,
expect: map[string]interface{}{"name": `em%GT)tqUDqz,i-\h+Mbqs-!:.m\\rE=mkbM#rR}@{-k@`}, expect: map[string]any{"name": `em%GT)tqUDqz,i-\h+Mbqs-!:.m\\rE=mkbM#rR}@{-k@`},
}, },
} }
@ -307,20 +307,20 @@ func TestParseLiteralInto(t *testing.T) {
tests := []struct { tests := []struct {
input string input string
input2 string input2 string
got map[string]interface{} got map[string]any
expect map[string]interface{} expect map[string]any
err bool err bool
}{ }{
{ {
input: "outer.inner1=value1,outer.inner3=value3,outer.inner4=4", input: "outer.inner1=value1,outer.inner3=value3,outer.inner4=4",
got: map[string]interface{}{ got: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "overwrite", "inner1": "overwrite",
"inner2": "value2", "inner2": "value2",
}, },
}, },
expect: map[string]interface{}{ expect: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "value1,outer.inner3=value3,outer.inner4=4", "inner1": "value1,outer.inner3=value3,outer.inner4=4",
"inner2": "value2", "inner2": "value2",
}}, }},
@ -329,9 +329,9 @@ func TestParseLiteralInto(t *testing.T) {
{ {
input: "listOuter[0][0].type=listValue", input: "listOuter[0][0].type=listValue",
input2: "listOuter[0][0].status=alive", input2: "listOuter[0][0].status=alive",
got: map[string]interface{}{}, got: map[string]any{},
expect: map[string]interface{}{ expect: map[string]any{
"listOuter": [][]interface{}{{map[string]string{ "listOuter": [][]any{{map[string]string{
"type": "listValue", "type": "listValue",
"status": "alive", "status": "alive",
}}}, }}},
@ -341,9 +341,9 @@ func TestParseLiteralInto(t *testing.T) {
{ {
input: "listOuter[0][0].type=listValue", input: "listOuter[0][0].type=listValue",
input2: "listOuter[1][0].status=alive", input2: "listOuter[1][0].status=alive",
got: map[string]interface{}{}, got: map[string]any{},
expect: map[string]interface{}{ expect: map[string]any{
"listOuter": [][]interface{}{ "listOuter": [][]any{
{ {
map[string]string{"type": "listValue"}, map[string]string{"type": "listValue"},
}, },
@ -357,17 +357,17 @@ func TestParseLiteralInto(t *testing.T) {
{ {
input: "listOuter[0][1][0].type=listValue", input: "listOuter[0][1][0].type=listValue",
input2: "listOuter[0][0][1].status=alive", input2: "listOuter[0][0][1].status=alive",
got: map[string]interface{}{ got: map[string]any{
"listOuter": []interface{}{ "listOuter": []any{
[]interface{}{ []any{
[]interface{}{ []any{
map[string]string{"exited": "old"}, map[string]string{"exited": "old"},
}, },
}, },
}, },
}, },
expect: map[string]interface{}{ expect: map[string]any{
"listOuter": [][][]interface{}{ "listOuter": [][][]any{
{ {
{ {
map[string]string{"exited": "old"}, map[string]string{"exited": "old"},
@ -429,13 +429,13 @@ func TestParseLiteralNestedLevels(t *testing.T) {
tests := []struct { tests := []struct {
str string str string
expect map[string]interface{} expect map[string]any
err bool err bool
errStr string errStr string
}{ }{
{ {
"outer.middle.inner=value", "outer.middle.inner=value",
map[string]interface{}{"outer": map[string]interface{}{"middle": map[string]interface{}{"inner": "value"}}}, map[string]any{"outer": map[string]any{"middle": map[string]any{"inner": "value"}}},
false, false,
"", "",
}, },

@ -26,48 +26,48 @@ import (
func TestSetIndex(t *testing.T) { func TestSetIndex(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
initial []interface{} initial []any
expect []interface{} expect []any
add int add int
val int val int
err bool err bool
}{ }{
{ {
name: "short", name: "short",
initial: []interface{}{0, 1}, initial: []any{0, 1},
expect: []interface{}{0, 1, 2}, expect: []any{0, 1, 2},
add: 2, add: 2,
val: 2, val: 2,
err: false, err: false,
}, },
{ {
name: "equal", name: "equal",
initial: []interface{}{0, 1}, initial: []any{0, 1},
expect: []interface{}{0, 2}, expect: []any{0, 2},
add: 1, add: 1,
val: 2, val: 2,
err: false, err: false,
}, },
{ {
name: "long", name: "long",
initial: []interface{}{0, 1, 2, 3, 4, 5}, initial: []any{0, 1, 2, 3, 4, 5},
expect: []interface{}{0, 1, 2, 4, 4, 5}, expect: []any{0, 1, 2, 4, 4, 5},
add: 3, add: 3,
val: 4, val: 4,
err: false, err: false,
}, },
{ {
name: "negative", name: "negative",
initial: []interface{}{0, 1, 2, 3, 4, 5}, initial: []any{0, 1, 2, 3, 4, 5},
expect: []interface{}{0, 1, 2, 3, 4, 5}, expect: []any{0, 1, 2, 3, 4, 5},
add: -1, add: -1,
val: 4, val: 4,
err: true, err: true,
}, },
{ {
name: "large", name: "large",
initial: []interface{}{0, 1, 2, 3, 4, 5}, initial: []any{0, 1, 2, 3, 4, 5},
expect: []interface{}{0, 1, 2, 3, 4, 5}, expect: []any{0, 1, 2, 3, 4, 5},
add: MaxIndex + 1, add: MaxIndex + 1,
val: 4, val: 4,
err: true, err: true,
@ -104,53 +104,53 @@ func TestSetIndex(t *testing.T) {
func TestParseSet(t *testing.T) { func TestParseSet(t *testing.T) {
testsString := []struct { testsString := []struct {
str string str string
expect map[string]interface{} expect map[string]any
err bool err bool
}{ }{
{ {
str: "long_int_string=1234567890", str: "long_int_string=1234567890",
expect: map[string]interface{}{"long_int_string": "1234567890"}, expect: map[string]any{"long_int_string": "1234567890"},
err: false, err: false,
}, },
{ {
str: "boolean=true", str: "boolean=true",
expect: map[string]interface{}{"boolean": "true"}, expect: map[string]any{"boolean": "true"},
err: false, err: false,
}, },
{ {
str: "is_null=null", str: "is_null=null",
expect: map[string]interface{}{"is_null": "null"}, expect: map[string]any{"is_null": "null"},
err: false, err: false,
}, },
{ {
str: "zero=0", str: "zero=0",
expect: map[string]interface{}{"zero": "0"}, expect: map[string]any{"zero": "0"},
err: false, err: false,
}, },
} }
tests := []struct { tests := []struct {
str string str string
expect map[string]interface{} expect map[string]any
err bool err bool
}{ }{
{ {
"name1=null,f=false,t=true", "name1=null,f=false,t=true",
map[string]interface{}{"name1": nil, "f": false, "t": true}, map[string]any{"name1": nil, "f": false, "t": true},
false, false,
}, },
{ {
"name1=value1", "name1=value1",
map[string]interface{}{"name1": "value1"}, map[string]any{"name1": "value1"},
false, false,
}, },
{ {
"name1=value1,name2=value2", "name1=value1,name2=value2",
map[string]interface{}{"name1": "value1", "name2": "value2"}, map[string]any{"name1": "value1", "name2": "value2"},
false, false,
}, },
{ {
"name1=value1,name2=value2,", "name1=value1,name2=value2,",
map[string]interface{}{"name1": "value1", "name2": "value2"}, map[string]any{"name1": "value1", "name2": "value2"},
false, false,
}, },
{ {
@ -159,27 +159,27 @@ func TestParseSet(t *testing.T) {
}, },
{ {
str: "name1=,name2=value2", str: "name1=,name2=value2",
expect: map[string]interface{}{"name1": "", "name2": "value2"}, expect: map[string]any{"name1": "", "name2": "value2"},
}, },
{ {
str: "leading_zeros=00009", str: "leading_zeros=00009",
expect: map[string]interface{}{"leading_zeros": "00009"}, expect: map[string]any{"leading_zeros": "00009"},
}, },
{ {
str: "zero_int=0", str: "zero_int=0",
expect: map[string]interface{}{"zero_int": 0}, expect: map[string]any{"zero_int": 0},
}, },
{ {
str: "long_int=1234567890", str: "long_int=1234567890",
expect: map[string]interface{}{"long_int": 1234567890}, expect: map[string]any{"long_int": 1234567890},
}, },
{ {
str: "boolean=true", str: "boolean=true",
expect: map[string]interface{}{"boolean": true}, expect: map[string]any{"boolean": true},
}, },
{ {
str: "is_null=null", str: "is_null=null",
expect: map[string]interface{}{"is_null": nil}, expect: map[string]any{"is_null": nil},
err: false, err: false,
}, },
{ {
@ -200,40 +200,40 @@ func TestParseSet(t *testing.T) {
}, },
{ {
"name1=one\\,two,name2=three\\,four", "name1=one\\,two,name2=three\\,four",
map[string]interface{}{"name1": "one,two", "name2": "three,four"}, map[string]any{"name1": "one,two", "name2": "three,four"},
false, false,
}, },
{ {
"name1=one\\=two,name2=three\\=four", "name1=one\\=two,name2=three\\=four",
map[string]interface{}{"name1": "one=two", "name2": "three=four"}, map[string]any{"name1": "one=two", "name2": "three=four"},
false, false,
}, },
{ {
"name1=one two three,name2=three two one", "name1=one two three,name2=three two one",
map[string]interface{}{"name1": "one two three", "name2": "three two one"}, map[string]any{"name1": "one two three", "name2": "three two one"},
false, false,
}, },
{ {
"outer.inner=value", "outer.inner=value",
map[string]interface{}{"outer": map[string]interface{}{"inner": "value"}}, map[string]any{"outer": map[string]any{"inner": "value"}},
false, false,
}, },
{ {
"outer.middle.inner=value", "outer.middle.inner=value",
map[string]interface{}{"outer": map[string]interface{}{"middle": map[string]interface{}{"inner": "value"}}}, map[string]any{"outer": map[string]any{"middle": map[string]any{"inner": "value"}}},
false, false,
}, },
{ {
"outer.inner1=value,outer.inner2=value2", "outer.inner1=value,outer.inner2=value2",
map[string]interface{}{"outer": map[string]interface{}{"inner1": "value", "inner2": "value2"}}, map[string]any{"outer": map[string]any{"inner1": "value", "inner2": "value2"}},
false, false,
}, },
{ {
"outer.inner1=value,outer.middle.inner=value", "outer.inner1=value,outer.middle.inner=value",
map[string]interface{}{ map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "value", "inner1": "value",
"middle": map[string]interface{}{ "middle": map[string]any{
"inner": "value", "inner": "value",
}, },
}, },
@ -250,7 +250,7 @@ func TestParseSet(t *testing.T) {
}, },
{ {
str: "name1.name2=", str: "name1.name2=",
expect: map[string]interface{}{"name1": map[string]interface{}{"name2": ""}}, expect: map[string]any{"name1": map[string]any{"name2": ""}},
}, },
{ {
str: "name1.=name2", str: "name1.=name2",
@ -262,12 +262,12 @@ func TestParseSet(t *testing.T) {
}, },
{ {
"name1={value1,value2}", "name1={value1,value2}",
map[string]interface{}{"name1": []string{"value1", "value2"}}, map[string]any{"name1": []string{"value1", "value2"}},
false, false,
}, },
{ {
"name1={value1,value2},name2={value1,value2}", "name1={value1,value2},name2={value1,value2}",
map[string]interface{}{ map[string]any{
"name1": []string{"value1", "value2"}, "name1": []string{"value1", "value2"},
"name2": []string{"value1", "value2"}, "name2": []string{"value1", "value2"},
}, },
@ -275,12 +275,12 @@ func TestParseSet(t *testing.T) {
}, },
{ {
"name1={1021,902}", "name1={1021,902}",
map[string]interface{}{"name1": []int{1021, 902}}, map[string]any{"name1": []int{1021, 902}},
false, false,
}, },
{ {
"name1.name2={value1,value2}", "name1.name2={value1,value2}",
map[string]interface{}{"name1": map[string]interface{}{"name2": []string{"value1", "value2"}}}, map[string]any{"name1": map[string]any{"name2": []string{"value1", "value2"}}},
false, false,
}, },
{ {
@ -290,21 +290,21 @@ func TestParseSet(t *testing.T) {
// List support // List support
{ {
str: "list[0]=foo", str: "list[0]=foo",
expect: map[string]interface{}{"list": []string{"foo"}}, expect: map[string]any{"list": []string{"foo"}},
}, },
{ {
str: "list[0].foo=bar", str: "list[0].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"list": []interface{}{ "list": []any{
map[string]interface{}{"foo": "bar"}, map[string]any{"foo": "bar"},
}, },
}, },
}, },
{ {
str: "list[0].foo=bar,list[0].hello=world", str: "list[0].foo=bar,list[0].hello=world",
expect: map[string]interface{}{ expect: map[string]any{
"list": []interface{}{ "list": []any{
map[string]interface{}{"foo": "bar", "hello": "world"}, map[string]any{"foo": "bar", "hello": "world"},
}, },
}, },
}, },
@ -314,15 +314,15 @@ func TestParseSet(t *testing.T) {
}, },
{ {
str: "list[0]=foo,list[1]=bar", str: "list[0]=foo,list[1]=bar",
expect: map[string]interface{}{"list": []string{"foo", "bar"}}, expect: map[string]any{"list": []string{"foo", "bar"}},
}, },
{ {
str: "list[0]=foo,list[1]=bar,", str: "list[0]=foo,list[1]=bar,",
expect: map[string]interface{}{"list": []string{"foo", "bar"}}, expect: map[string]any{"list": []string{"foo", "bar"}},
}, },
{ {
str: "list[0]=foo,list[3]=bar", str: "list[0]=foo,list[3]=bar",
expect: map[string]interface{}{"list": []interface{}{"foo", nil, nil, "bar"}}, expect: map[string]any{"list": []any{"foo", nil, nil, "bar"}},
}, },
{ {
str: "list[0]=foo,list[-20]=bar", str: "list[0]=foo,list[-20]=bar",
@ -334,41 +334,41 @@ func TestParseSet(t *testing.T) {
}, },
{ {
str: "noval[0]", str: "noval[0]",
expect: map[string]interface{}{"noval": []interface{}{}}, expect: map[string]any{"noval": []any{}},
}, },
{ {
str: "noval[0]=", str: "noval[0]=",
expect: map[string]interface{}{"noval": []interface{}{""}}, expect: map[string]any{"noval": []any{""}},
}, },
{ {
str: "nested[0][0]=1", str: "nested[0][0]=1",
expect: map[string]interface{}{"nested": []interface{}{[]interface{}{1}}}, expect: map[string]any{"nested": []any{[]any{1}}},
}, },
{ {
str: "nested[1][1]=1", str: "nested[1][1]=1",
expect: map[string]interface{}{"nested": []interface{}{nil, []interface{}{nil, 1}}}, expect: map[string]any{"nested": []any{nil, []any{nil, 1}}},
}, },
{ {
str: "name1.name2[0].foo=bar,name1.name2[1].foo=bar", str: "name1.name2[0].foo=bar,name1.name2[1].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"name1": map[string]interface{}{ "name1": map[string]any{
"name2": []map[string]interface{}{{"foo": "bar"}, {"foo": "bar"}}, "name2": []map[string]any{{"foo": "bar"}, {"foo": "bar"}},
}, },
}, },
}, },
{ {
str: "name1.name2[1].foo=bar,name1.name2[0].foo=bar", str: "name1.name2[1].foo=bar,name1.name2[0].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"name1": map[string]interface{}{ "name1": map[string]any{
"name2": []map[string]interface{}{{"foo": "bar"}, {"foo": "bar"}}, "name2": []map[string]any{{"foo": "bar"}, {"foo": "bar"}},
}, },
}, },
}, },
{ {
str: "name1.name2[1].foo=bar", str: "name1.name2[1].foo=bar",
expect: map[string]interface{}{ expect: map[string]any{
"name1": map[string]interface{}{ "name1": map[string]any{
"name2": []map[string]interface{}{nil, {"foo": "bar"}}, "name2": []map[string]any{nil, {"foo": "bar"}},
}, },
}, },
}, },
@ -434,20 +434,20 @@ func TestParseInto(t *testing.T) {
tests := []struct { tests := []struct {
input string input string
input2 string input2 string
got map[string]interface{} got map[string]any
expect map[string]interface{} expect map[string]any
err bool err bool
}{ }{
{ {
input: "outer.inner1=value1,outer.inner3=value3,outer.inner4=4", input: "outer.inner1=value1,outer.inner3=value3,outer.inner4=4",
got: map[string]interface{}{ got: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "overwrite", "inner1": "overwrite",
"inner2": "value2", "inner2": "value2",
}, },
}, },
expect: map[string]interface{}{ expect: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "value1", "inner1": "value1",
"inner2": "value2", "inner2": "value2",
"inner3": "value3", "inner3": "value3",
@ -458,9 +458,9 @@ func TestParseInto(t *testing.T) {
{ {
input: "listOuter[0][0].type=listValue", input: "listOuter[0][0].type=listValue",
input2: "listOuter[0][0].status=alive", input2: "listOuter[0][0].status=alive",
got: map[string]interface{}{}, got: map[string]any{},
expect: map[string]interface{}{ expect: map[string]any{
"listOuter": [][]interface{}{{map[string]string{ "listOuter": [][]any{{map[string]string{
"type": "listValue", "type": "listValue",
"status": "alive", "status": "alive",
}}}, }}},
@ -470,9 +470,9 @@ func TestParseInto(t *testing.T) {
{ {
input: "listOuter[0][0].type=listValue", input: "listOuter[0][0].type=listValue",
input2: "listOuter[1][0].status=alive", input2: "listOuter[1][0].status=alive",
got: map[string]interface{}{}, got: map[string]any{},
expect: map[string]interface{}{ expect: map[string]any{
"listOuter": [][]interface{}{ "listOuter": [][]any{
{ {
map[string]string{"type": "listValue"}, map[string]string{"type": "listValue"},
}, },
@ -486,17 +486,17 @@ func TestParseInto(t *testing.T) {
{ {
input: "listOuter[0][1][0].type=listValue", input: "listOuter[0][1][0].type=listValue",
input2: "listOuter[0][0][1].status=alive", input2: "listOuter[0][0][1].status=alive",
got: map[string]interface{}{ got: map[string]any{
"listOuter": []interface{}{ "listOuter": []any{
[]interface{}{ []any{
[]interface{}{ []any{
map[string]string{"exited": "old"}, map[string]string{"exited": "old"},
}, },
}, },
}, },
}, },
expect: map[string]interface{}{ expect: map[string]any{
"listOuter": [][][]interface{}{ "listOuter": [][][]any{
{ {
{ {
map[string]string{"exited": "old"}, map[string]string{"exited": "old"},
@ -544,15 +544,15 @@ func TestParseInto(t *testing.T) {
} }
func TestParseIntoString(t *testing.T) { func TestParseIntoString(t *testing.T) {
got := map[string]interface{}{ got := map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "overwrite", "inner1": "overwrite",
"inner2": "value2", "inner2": "value2",
}, },
} }
input := "outer.inner1=1,outer.inner3=3" input := "outer.inner1=1,outer.inner3=3"
expect := map[string]interface{}{ expect := map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "1", "inner1": "1",
"inner2": "value2", "inner2": "value2",
"inner3": "3", "inner3": "3",
@ -580,20 +580,20 @@ func TestParseIntoString(t *testing.T) {
func TestParseJSON(t *testing.T) { func TestParseJSON(t *testing.T) {
tests := []struct { tests := []struct {
input string input string
got map[string]interface{} got map[string]any
expect map[string]interface{} expect map[string]any
err bool err bool
}{ }{
{ // set json scalars values, and replace one existing key { // set json scalars values, and replace one existing key
input: "outer.inner1=\"1\",outer.inner3=3,outer.inner4=true,outer.inner5=\"true\"", input: "outer.inner1=\"1\",outer.inner3=3,outer.inner4=true,outer.inner5=\"true\"",
got: map[string]interface{}{ got: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "overwrite", "inner1": "overwrite",
"inner2": "value2", "inner2": "value2",
}, },
}, },
expect: map[string]interface{}{ expect: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": "1", "inner1": "1",
"inner2": "value2", "inner2": "value2",
"inner3": 3, "inner3": 3,
@ -605,43 +605,43 @@ func TestParseJSON(t *testing.T) {
}, },
{ // set json objects and arrays, and replace one existing key { // set json objects and arrays, and replace one existing key
input: "outer.inner1={\"a\":\"1\",\"b\":2,\"c\":[1,2,3]},outer.inner3=[\"new value 1\",\"new value 2\"],outer.inner4={\"aa\":\"1\",\"bb\":2,\"cc\":[1,2,3]},outer.inner5=[{\"A\":\"1\",\"B\":2,\"C\":[1,2,3]}]", input: "outer.inner1={\"a\":\"1\",\"b\":2,\"c\":[1,2,3]},outer.inner3=[\"new value 1\",\"new value 2\"],outer.inner4={\"aa\":\"1\",\"bb\":2,\"cc\":[1,2,3]},outer.inner5=[{\"A\":\"1\",\"B\":2,\"C\":[1,2,3]}]",
got: map[string]interface{}{ got: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": map[string]interface{}{ "inner1": map[string]any{
"x": "overwrite", "x": "overwrite",
}, },
"inner2": "value2", "inner2": "value2",
"inner3": []interface{}{ "inner3": []any{
"overwrite", "overwrite",
}, },
}, },
}, },
expect: map[string]interface{}{ expect: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": map[string]interface{}{"a": "1", "b": 2, "c": []interface{}{1, 2, 3}}, "inner1": map[string]any{"a": "1", "b": 2, "c": []any{1, 2, 3}},
"inner2": "value2", "inner2": "value2",
"inner3": []interface{}{"new value 1", "new value 2"}, "inner3": []any{"new value 1", "new value 2"},
"inner4": map[string]interface{}{"aa": "1", "bb": 2, "cc": []interface{}{1, 2, 3}}, "inner4": map[string]any{"aa": "1", "bb": 2, "cc": []any{1, 2, 3}},
"inner5": []interface{}{map[string]interface{}{"A": "1", "B": 2, "C": []interface{}{1, 2, 3}}}, "inner5": []any{map[string]any{"A": "1", "B": 2, "C": []any{1, 2, 3}}},
}, },
}, },
err: false, err: false,
}, },
{ // null assignment, and no value assigned (equivalent to null) { // null assignment, and no value assigned (equivalent to null)
input: "outer.inner1=,outer.inner3={\"aa\":\"1\",\"bb\":2,\"cc\":[1,2,3]},outer.inner3.cc[1]=null", input: "outer.inner1=,outer.inner3={\"aa\":\"1\",\"bb\":2,\"cc\":[1,2,3]},outer.inner3.cc[1]=null",
got: map[string]interface{}{ got: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": map[string]interface{}{ "inner1": map[string]any{
"x": "overwrite", "x": "overwrite",
}, },
"inner2": "value2", "inner2": "value2",
}, },
}, },
expect: map[string]interface{}{ expect: map[string]any{
"outer": map[string]interface{}{ "outer": map[string]any{
"inner1": nil, "inner1": nil,
"inner2": "value2", "inner2": "value2",
"inner3": map[string]interface{}{"aa": "1", "bb": 2, "cc": []interface{}{1, nil, 3}}, "inner3": map[string]any{"aa": "1", "bb": 2, "cc": []any{1, nil, 3}},
}, },
}, },
err: false, err: false,
@ -680,10 +680,10 @@ func TestParseJSON(t *testing.T) {
func TestParseFile(t *testing.T) { func TestParseFile(t *testing.T) {
input := "name1=path1" input := "name1=path1"
expect := map[string]interface{}{ expect := map[string]any{
"name1": "value1", "name1": "value1",
} }
rs2v := func(rs []rune) (interface{}, error) { rs2v := func(rs []rune) (any, error) {
v := string(rs) v := string(rs)
if v != "path1" { if v != "path1" {
t.Errorf("%s: runesToVal: Expected value path1, got %s", input, v) t.Errorf("%s: runesToVal: Expected value path1, got %s", input, v)
@ -712,12 +712,12 @@ func TestParseFile(t *testing.T) {
} }
func TestParseIntoFile(t *testing.T) { func TestParseIntoFile(t *testing.T) {
got := map[string]interface{}{} got := map[string]any{}
input := "name1=path1" input := "name1=path1"
expect := map[string]interface{}{ expect := map[string]any{
"name1": "value1", "name1": "value1",
} }
rs2v := func(rs []rune) (interface{}, error) { rs2v := func(rs []rune) (any, error) {
v := string(rs) v := string(rs)
if v != "path1" { if v != "path1" {
t.Errorf("%s: runesToVal: Expected value path1, got %s", input, v) t.Errorf("%s: runesToVal: Expected value path1, got %s", input, v)
@ -768,13 +768,13 @@ func TestParseSetNestedLevels(t *testing.T) {
} }
tests := []struct { tests := []struct {
str string str string
expect map[string]interface{} expect map[string]any
err bool err bool
errStr string errStr string
}{ }{
{ {
"outer.middle.inner=value", "outer.middle.inner=value",
map[string]interface{}{"outer": map[string]interface{}{"middle": map[string]interface{}{"inner": "value"}}}, map[string]any{"outer": map[string]any{"middle": map[string]any{"inner": "value"}}},
false, false,
"", "",
}, },

Loading…
Cancel
Save