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

chore(pkg): fix modernize linter
pull/31128/head
Terry Howe 6 days 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
// - A chart has access to all of the variables for it, as well as all of
// 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)
if err != nil {
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
// logic need to retain them for when Coalescing will happen again later in the
// 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)
if err != nil {
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)
}
func copyValues(vals map[string]interface{}) (common.Values, error) {
func copyValues(vals map[string]any) (common.Values, error) {
v, err := copystructure.Copy(vals)
if err != nil {
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 valsCopy == nil {
valsCopy = make(map[string]interface{})
valsCopy = make(map[string]any)
}
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.
//
@ -96,13 +96,13 @@ type printFn func(format string, v ...interface{})
// Note, the merge argument specifies whether this is being used by MergeValues
// or CoalesceValues. Coalescing removes null values and their keys in some
// 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)
return coalesceDeps(printf, ch, dest, prefix, merge)
}
// 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)
if err != nil {
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 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) {
return dest, fmt.Errorf("type mismatch on %s: %t", sub.Name(), c)
}
if dv, ok := dest[sub.Name()]; ok {
dvmap := dv.(map[string]interface{})
dvmap := dv.(map[string]any)
subPrefix := concatPrefix(prefix, ch.Name())
// Get globals out of dest and merge them into dvmap.
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.
//
// For convenience, returns dest.
func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix string, _ bool) {
var dg, sg map[string]interface{}
func coalesceGlobals(printf printFn, dest, src map[string]any, prefix string, _ bool) {
var dg, sg map[string]any
if destglob, ok := dest[common.GlobalKey]; !ok {
dg = make(map[string]interface{})
} else if dg, ok = destglob.(map[string]interface{}); !ok {
dg = make(map[string]any)
} else if dg, ok = destglob.(map[string]any); !ok {
printf("warning: skipping globals because destination %s is not a table.", common.GlobalKey)
return
}
if srcglob, ok := src[common.GlobalKey]; !ok {
sg = make(map[string]interface{})
} else if sg, ok = srcglob.(map[string]interface{}); !ok {
sg = make(map[string]any)
} else if sg, ok = srcglob.(map[string]any); !ok {
printf("warning: skipping globals because source %s is not a table.", common.GlobalKey)
return
}
@ -160,12 +160,12 @@ func coalesceGlobals(printf printFn, dest, src map[string]interface{}, prefix st
// tables in globals.
for key, val := range sg {
if istable(val) {
vv := copyMap(val.(map[string]interface{}))
vv := copyMap(val.(map[string]any))
if destv, ok := dg[key]; !ok {
// Here there is no merge. We're just adding.
dg[key] = vv
} 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)
} else {
// 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
}
func copyMap(src map[string]interface{}) map[string]interface{} {
m := make(map[string]interface{}, len(src))
func copyMap(src map[string]any) map[string]any {
m := make(map[string]any, len(src))
maps.Copy(m, src)
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.
//
// 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)
if err != nil {
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.
// This section is fault-tolerant as there is no ability to return an error.
valuesCopy, err := copystructure.Copy(ch.Values())
var vc map[string]interface{}
var vc map[string]any
var ok bool
if err != nil {
// 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)
vc = ch.Values()
} else {
vc, ok = valuesCopy.(map[string]interface{})
vc, ok = valuesCopy.(map[string]any)
if !ok {
// c.Values has a map[string]interface{} structure. If the copy of
// 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
// remove incompatible keys from any previous chart, file, or set values.
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].
src, ok := val.(map[string]interface{})
src, ok := val.(map[string]any)
if !ok {
// If the original value is nil, there is nothing to coalesce, so we don't print
// 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.
//
// 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)
}
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)
}
// coalesceTablesFullKey merges a source map into a destination map.
//
// 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
if src == nil {
return dst
@ -330,7 +330,7 @@ func coalesceTablesFullKey(printf printFn, dst, src map[string]interface{}, pref
dst[key] = val
} else if istable(val) {
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 {
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.
func istable(v interface{}) bool {
_, ok := v.(map[string]interface{})
func istable(v any) bool {
_, ok := v.(map[string]any)
return ok
}

@ -75,65 +75,65 @@ func TestCoalesceValues(t *testing.T) {
c := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "moby"},
Values: map[string]interface{}{
Values: map[string]any{
"back": "exists",
"bottom": "exists",
"front": "exists",
"left": "exists",
"name": "moby",
"nested": map[string]interface{}{"boat": true},
"nested": map[string]any{"boat": true},
"override": "bad",
"right": "exists",
"scope": "moby",
"top": "nope",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l0": "moby"},
"global": map[string]any{
"nested2": map[string]any{"l0": "moby"},
},
"pequod": map[string]interface{}{
"pequod": map[string]any{
"boat": "maybe",
"ahab": map[string]interface{}{
"ahab": map[string]any{
"boat": "maybe",
"nested": map[string]interface{}{"boat": "maybe"},
"nested": map[string]any{"boat": "maybe"},
},
},
},
},
withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "pequod"},
Values: map[string]interface{}{
Values: map[string]any{
"name": "pequod",
"scope": "pequod",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l1": "pequod"},
"global": map[string]any{
"nested2": map[string]any{"l1": "pequod"},
},
"boat": false,
"ahab": map[string]interface{}{
"ahab": map[string]any{
"boat": false,
"nested": map[string]interface{}{"boat": false},
"nested": map[string]any{"boat": false},
},
},
},
&chart.Chart{
Metadata: &chart.Metadata{Name: "ahab"},
Values: map[string]interface{}{
"global": map[string]interface{}{
"nested": map[string]interface{}{"foo": "bar", "foo2": "bar2"},
"nested2": map[string]interface{}{"l2": "ahab"},
Values: map[string]any{
"global": map[string]any{
"nested": map[string]any{"foo": "bar", "foo2": "bar2"},
"nested2": map[string]any{"l2": "ahab"},
},
"scope": "ahab",
"name": "ahab",
"boat": true,
"nested": map[string]interface{}{"foo": false, "boat": true},
"object": map[string]interface{}{"foo": "bar"},
"nested": map[string]any{"foo": false, "boat": true},
"object": map[string]any{"foo": "bar"},
},
},
),
&chart.Chart{
Metadata: &chart.Metadata{Name: "spouter"},
Values: map[string]interface{}{
Values: map[string]any{
"scope": "spouter",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l1": "spouter"},
"global": map[string]any{
"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")
}
subchart := v["pequod"].(map[string]interface{})
subchart := v["pequod"].(map[string]any)
if _, ok := subchart["boat"]; ok {
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 {
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")
}
@ -241,7 +241,7 @@ func TestCoalesceValues(t *testing.T) {
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
tt := template.Must(template.New("t").Parse(tpl))
err := tt.Execute(&b, v)
@ -253,52 +253,52 @@ func TestMergeValues(t *testing.T) {
c := withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "moby"},
Values: map[string]interface{}{
Values: map[string]any{
"back": "exists",
"bottom": "exists",
"front": "exists",
"left": "exists",
"name": "moby",
"nested": map[string]interface{}{"boat": true},
"nested": map[string]any{"boat": true},
"override": "bad",
"right": "exists",
"scope": "moby",
"top": "nope",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l0": "moby"},
"global": map[string]any{
"nested2": map[string]any{"l0": "moby"},
},
},
},
withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "pequod"},
Values: map[string]interface{}{
Values: map[string]any{
"name": "pequod",
"scope": "pequod",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l1": "pequod"},
"global": map[string]any{
"nested2": map[string]any{"l1": "pequod"},
},
},
},
&chart.Chart{
Metadata: &chart.Metadata{Name: "ahab"},
Values: map[string]interface{}{
"global": map[string]interface{}{
"nested": map[string]interface{}{"foo": "bar"},
"nested2": map[string]interface{}{"l2": "ahab"},
Values: map[string]any{
"global": map[string]any{
"nested": map[string]any{"foo": "bar"},
"nested2": map[string]any{"l2": "ahab"},
},
"scope": "ahab",
"name": "ahab",
"boat": true,
"nested": map[string]interface{}{"foo": false, "bar": true},
"nested": map[string]any{"foo": false, "bar": true},
},
},
),
&chart.Chart{
Metadata: &chart.Metadata{Name: "spouter"},
Values: map[string]interface{}{
Values: map[string]any{
"scope": "spouter",
"global": map[string]interface{}{
"nested2": map[string]interface{}{"l1": "spouter"},
"global": map[string]any{
"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")
}
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 {
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")
}
@ -401,28 +401,28 @@ func TestMergeValues(t *testing.T) {
}
func TestCoalesceTables(t *testing.T) {
dst := map[string]interface{}{
dst := map[string]any{
"name": "Ishmael",
"address": map[string]interface{}{
"address": map[string]any{
"street": "123 Spouter Inn Ct.",
"city": "Nantucket",
"country": nil,
},
"details": map[string]interface{}{
"details": map[string]any{
"friends": []string{"Tashtego"},
},
"boat": "pequod",
"hole": nil,
}
src := map[string]interface{}{
src := map[string]any{
"occupation": "whaler",
"address": map[string]interface{}{
"address": map[string]any{
"state": "MA",
"street": "234 Spouter Inn Ct.",
"country": "US",
},
"details": "empty",
"boat": map[string]interface{}{
"boat": map[string]any{
"mast": true,
},
"hole": "black",
@ -439,7 +439,7 @@ func TestCoalesceTables(t *testing.T) {
t.Errorf("Unexpected occupation: %s", dst["occupation"])
}
addr, ok := dst["address"].(map[string]interface{})
addr, ok := dst["address"].(map[string]any)
if !ok {
t.Fatal("Address went away.")
}
@ -460,7 +460,7 @@ func TestCoalesceTables(t *testing.T) {
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"])
} else if _, ok := det["friends"]; !ok {
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.")
}
dst2 := map[string]interface{}{
dst2 := map[string]any{
"name": "Ishmael",
"address": map[string]interface{}{
"address": map[string]any{
"street": "123 Spouter Inn Ct.",
"city": "Nantucket",
"country": "US",
},
"details": map[string]interface{}{
"details": map[string]any{
"friends": []string{"Tashtego"},
},
"boat": "pequod",
@ -496,7 +496,7 @@ func TestCoalesceTables(t *testing.T) {
t.Errorf("Unexpected name: %s", dst2["name"])
}
addr2, ok := dst2["address"].(map[string]interface{})
addr2, ok := dst2["address"].(map[string]any)
if !ok {
t.Fatal("Address went away.")
}
@ -513,7 +513,7 @@ func TestCoalesceTables(t *testing.T) {
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"])
} else if _, ok := det2["friends"]; !ok {
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) {
dst := map[string]interface{}{
dst := map[string]any{
"name": "Ishmael",
"address": map[string]interface{}{
"address": map[string]any{
"street": "123 Spouter Inn Ct.",
"city": "Nantucket",
"country": nil,
},
"details": map[string]interface{}{
"details": map[string]any{
"friends": []string{"Tashtego"},
},
"boat": "pequod",
"hole": nil,
}
src := map[string]interface{}{
src := map[string]any{
"occupation": "whaler",
"address": map[string]interface{}{
"address": map[string]any{
"state": "MA",
"street": "234 Spouter Inn Ct.",
"country": "US",
},
"details": "empty",
"boat": map[string]interface{}{
"boat": map[string]any{
"mast": true,
},
"hole": "black",
@ -567,7 +567,7 @@ func TestMergeTables(t *testing.T) {
t.Errorf("Unexpected occupation: %s", dst["occupation"])
}
addr, ok := dst["address"].(map[string]interface{})
addr, ok := dst["address"].(map[string]any)
if !ok {
t.Fatal("Address went away.")
}
@ -590,7 +590,7 @@ func TestMergeTables(t *testing.T) {
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"])
} else if _, ok := det["friends"]; !ok {
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.")
}
dst2 := map[string]interface{}{
dst2 := map[string]any{
"name": "Ishmael",
"address": map[string]interface{}{
"address": map[string]any{
"street": "123 Spouter Inn Ct.",
"city": "Nantucket",
"country": "US",
},
"details": map[string]interface{}{
"details": map[string]any{
"friends": []string{"Tashtego"},
},
"boat": "pequod",
@ -629,7 +629,7 @@ func TestMergeTables(t *testing.T) {
t.Errorf("Unexpected name: %s", dst2["name"])
}
addr2, ok := dst2["address"].(map[string]interface{})
addr2, ok := dst2["address"].(map[string]any)
if !ok {
t.Fatal("Address went away.")
}
@ -646,7 +646,7 @@ func TestMergeTables(t *testing.T) {
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"])
} else if _, ok := det2["friends"]; !ok {
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{
Metadata: &chart.Metadata{Name: "level1"},
Values: map[string]interface{}{
Values: map[string]any{
"name": "moby",
},
},
withDeps(&chart.Chart{
Metadata: &chart.Metadata{Name: "level2"},
Values: map[string]interface{}{
Values: map[string]any{
"name": "pequod",
},
},
&chart.Chart{
Metadata: &chart.Metadata{Name: "level3"},
Values: map[string]interface{}{
Values: map[string]any{
"name": "ahab",
"boat": true,
"spear": map[string]interface{}{
"spear": map[string]any{
"tip": true,
"sail": map[string]interface{}{
"sail": map[string]any{
"cotton": true,
},
},
@ -695,12 +695,12 @@ func TestCoalesceValuesWarnings(t *testing.T) {
),
)
vals := map[string]interface{}{
"level2": map[string]interface{}{
"level3": map[string]interface{}{
"boat": map[string]interface{}{"mast": true},
"spear": map[string]interface{}{
"tip": map[string]interface{}{
vals := map[string]any{
"level2": map[string]any{
"level3": map[string]any{
"boat": map[string]any{"mast": true},
"spear": map[string]any{
"tip": map[string]any{
"sharp": true,
},
"sail": true,
@ -710,7 +710,7 @@ func TestCoalesceValuesWarnings(t *testing.T) {
}
warnings := make([]string, 0)
printf := func(format string, v ...interface{}) {
printf := func(format string, v ...any) {
t.Logf(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)
}
var m map[string]interface{}
var m map[string]any
if err := yaml.Unmarshal(transform(string(b), schart.Name()), &m); err != nil {
return fmt.Errorf("transforming values file: %w", err)
}

@ -26,7 +26,7 @@ import (
func TestParseLiteral(t *testing.T) {
cases := []struct {
str string
expect map[string]interface{}
expect map[string]any
err bool
}{
{
@ -35,61 +35,61 @@ func TestParseLiteral(t *testing.T) {
},
{
str: "name=",
expect: map[string]interface{}{"name": ""},
expect: map[string]any{"name": ""},
},
{
str: "name=value",
expect: map[string]interface{}{"name": "value"},
expect: map[string]any{"name": "value"},
err: false,
},
{
str: "long_int_string=1234567890",
expect: map[string]interface{}{"long_int_string": "1234567890"},
expect: map[string]any{"long_int_string": "1234567890"},
err: false,
},
{
str: "boolean=true",
expect: map[string]interface{}{"boolean": "true"},
expect: map[string]any{"boolean": "true"},
err: false,
},
{
str: "is_null=null",
expect: map[string]interface{}{"is_null": "null"},
expect: map[string]any{"is_null": "null"},
err: false,
},
{
str: "zero=0",
expect: map[string]interface{}{"zero": "0"},
expect: map[string]any{"zero": "0"},
err: false,
},
{
str: "name1=null,name2=value2",
expect: map[string]interface{}{"name1": "null,name2=value2"},
expect: map[string]any{"name1": "null,name2=value2"},
err: false,
},
{
str: "name1=value,,,tail",
expect: map[string]interface{}{"name1": "value,,,tail"},
expect: map[string]any{"name1": "value,,,tail"},
err: false,
},
{
str: "leading_zeros=00009",
expect: map[string]interface{}{"leading_zeros": "00009"},
expect: map[string]any{"leading_zeros": "00009"},
err: false,
},
{
str: "name=one two three",
expect: map[string]interface{}{"name": "one two three"},
expect: map[string]any{"name": "one two three"},
err: false,
},
{
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,
},
{
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,
},
{
@ -98,7 +98,7 @@ func TestParseLiteral(t *testing.T) {
},
{
str: "name1.name2=",
expect: map[string]interface{}{"name1": map[string]interface{}{"name2": ""}},
expect: map[string]any{"name1": map[string]any{"name2": ""}},
err: false,
},
{
@ -111,20 +111,20 @@ func TestParseLiteral(t *testing.T) {
},
{
str: "name1={value1,value2}",
expect: map[string]interface{}{"name1": "{value1,value2}"},
expect: map[string]any{"name1": "{value1,value2}"},
},
// List support
{
str: "list[0]=foo",
expect: map[string]interface{}{"list": []string{"foo"}},
expect: map[string]any{"list": []string{"foo"}},
err: false,
},
{
str: "list[0].foo=bar",
expect: map[string]interface{}{
"list": []interface{}{
map[string]interface{}{"foo": "bar"},
expect: map[string]any{
"list": []any{
map[string]any{"foo": "bar"},
},
},
err: false,
@ -135,7 +135,7 @@ func TestParseLiteral(t *testing.T) {
},
{
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,
},
{
@ -144,133 +144,133 @@ func TestParseLiteral(t *testing.T) {
},
{
str: "noval[0]",
expect: map[string]interface{}{"noval": []interface{}{}},
expect: map[string]any{"noval": []any{}},
err: false,
},
{
str: "noval[0]=",
expect: map[string]interface{}{"noval": []interface{}{""}},
expect: map[string]any{"noval": []any{""}},
err: false,
},
{
str: "nested[0][0]=1",
expect: map[string]interface{}{"nested": []interface{}{[]interface{}{"1"}}},
expect: map[string]any{"nested": []any{[]any{"1"}}},
err: false,
},
{
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,
},
{
str: "name1.name2[0].foo=bar",
expect: map[string]interface{}{
"name1": map[string]interface{}{
"name2": []map[string]interface{}{{"foo": "bar"}},
expect: map[string]any{
"name1": map[string]any{
"name2": []map[string]any{{"foo": "bar"}},
},
},
},
{
str: "name1.name2[1].foo=bar",
expect: map[string]interface{}{
"name1": map[string]interface{}{
"name2": []map[string]interface{}{nil, {"foo": "bar"}},
expect: map[string]any{
"name1": map[string]any{
"name2": []map[string]any{nil, {"foo": "bar"}},
},
},
},
{
str: "name1.name2[1].foo=bar",
expect: map[string]interface{}{
"name1": map[string]interface{}{
"name2": []map[string]interface{}{nil, {"foo": "bar"}},
expect: map[string]any{
"name1": map[string]any{
"name2": []map[string]any{nil, {"foo": "bar"}},
},
},
},
{
str: "]={}].",
expect: map[string]interface{}{"]": "{}]."},
expect: map[string]any{"]": "{}]."},
err: false,
},
// issue test cases: , = $ ( ) { } . \ \\
{
str: "name=val,val",
expect: map[string]interface{}{"name": "val,val"},
expect: map[string]any{"name": "val,val"},
err: false,
},
{
str: "name=val.val",
expect: map[string]interface{}{"name": "val.val"},
expect: map[string]any{"name": "val.val"},
err: false,
},
{
str: "name=val=val",
expect: map[string]interface{}{"name": "val=val"},
expect: map[string]any{"name": "val=val"},
err: false,
},
{
str: "name=val$val",
expect: map[string]interface{}{"name": "val$val"},
expect: map[string]any{"name": "val$val"},
err: false,
},
{
str: "name=(value",
expect: map[string]interface{}{"name": "(value"},
expect: map[string]any{"name": "(value"},
err: false,
},
{
str: "name=value)",
expect: map[string]interface{}{"name": "value)"},
expect: map[string]any{"name": "value)"},
err: false,
},
{
str: "name=(value)",
expect: map[string]interface{}{"name": "(value)"},
expect: map[string]any{"name": "(value)"},
err: false,
},
{
str: "name={value",
expect: map[string]interface{}{"name": "{value"},
expect: map[string]any{"name": "{value"},
err: false,
},
{
str: "name=value}",
expect: map[string]interface{}{"name": "value}"},
expect: map[string]any{"name": "value}"},
err: false,
},
{
str: "name={value}",
expect: map[string]interface{}{"name": "{value}"},
expect: map[string]any{"name": "{value}"},
err: false,
},
{
str: "name={value1,value2}",
expect: map[string]interface{}{"name": "{value1,value2}"},
expect: map[string]any{"name": "{value1,value2}"},
err: false,
},
{
str: `name=val\val`,
expect: map[string]interface{}{"name": `val\val`},
expect: map[string]any{"name": `val\val`},
err: false,
},
{
str: `name=val\\val`,
expect: map[string]interface{}{"name": `val\\val`},
expect: map[string]any{"name": `val\\val`},
err: false,
},
{
str: `name=val\\\val`,
expect: map[string]interface{}{"name": `val\\\val`},
expect: map[string]any{"name": `val\\\val`},
err: false,
},
{
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,
},
{
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 {
input string
input2 string
got map[string]interface{}
expect map[string]interface{}
got map[string]any
expect map[string]any
err bool
}{
{
input: "outer.inner1=value1,outer.inner3=value3,outer.inner4=4",
got: map[string]interface{}{
"outer": map[string]interface{}{
got: map[string]any{
"outer": map[string]any{
"inner1": "overwrite",
"inner2": "value2",
},
},
expect: map[string]interface{}{
"outer": map[string]interface{}{
expect: map[string]any{
"outer": map[string]any{
"inner1": "value1,outer.inner3=value3,outer.inner4=4",
"inner2": "value2",
}},
@ -329,9 +329,9 @@ func TestParseLiteralInto(t *testing.T) {
{
input: "listOuter[0][0].type=listValue",
input2: "listOuter[0][0].status=alive",
got: map[string]interface{}{},
expect: map[string]interface{}{
"listOuter": [][]interface{}{{map[string]string{
got: map[string]any{},
expect: map[string]any{
"listOuter": [][]any{{map[string]string{
"type": "listValue",
"status": "alive",
}}},
@ -341,9 +341,9 @@ func TestParseLiteralInto(t *testing.T) {
{
input: "listOuter[0][0].type=listValue",
input2: "listOuter[1][0].status=alive",
got: map[string]interface{}{},
expect: map[string]interface{}{
"listOuter": [][]interface{}{
got: map[string]any{},
expect: map[string]any{
"listOuter": [][]any{
{
map[string]string{"type": "listValue"},
},
@ -357,17 +357,17 @@ func TestParseLiteralInto(t *testing.T) {
{
input: "listOuter[0][1][0].type=listValue",
input2: "listOuter[0][0][1].status=alive",
got: map[string]interface{}{
"listOuter": []interface{}{
[]interface{}{
[]interface{}{
got: map[string]any{
"listOuter": []any{
[]any{
[]any{
map[string]string{"exited": "old"},
},
},
},
},
expect: map[string]interface{}{
"listOuter": [][][]interface{}{
expect: map[string]any{
"listOuter": [][][]any{
{
{
map[string]string{"exited": "old"},
@ -429,13 +429,13 @@ func TestParseLiteralNestedLevels(t *testing.T) {
tests := []struct {
str string
expect map[string]interface{}
expect map[string]any
err bool
errStr string
}{
{
"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,
"",
},

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

Loading…
Cancel
Save