diff --git a/util/expand/expand.go b/util/expand/expand.go index 93457698eb89..04c6f68e0bf7 100644 --- a/util/expand/expand.go +++ b/util/expand/expand.go @@ -26,7 +26,7 @@ func removeConflicts(m map[string]interface{}) map[string]interface{} { for i := 0; i < len(keys)-1; i++ { k := keys[i] // remove any parent that has a child - if strings.HasPrefix(keys[i+1]+".", k) { + if strings.HasPrefix(keys[i+1], k+".") { delete(n, k) } } diff --git a/util/expand/expand_test.go b/util/expand/expand_test.go index 6f7ced136578..c6139498aadb 100644 --- a/util/expand/expand_test.go +++ b/util/expand/expand_test.go @@ -8,20 +8,26 @@ import ( ) func TestExpand(t *testing.T) { - for i := 0; i < 100; i++ { // loop 100 times, because map ordering is not determisitic + for i := 0; i < 1; i++ { // loop 100 times, because map ordering is not determisitic t.Run(fmt.Sprint(i), func(t *testing.T) { before := map[string]interface{}{ - "a.b": 1, - "a": 2, - "ab": 3, + "a.b": 1, + "a.c.d": 2, + "a": 3, // should be deleted + "ab": 4, + "abb": 5, // should be kept } after := Expand(before) - assert.Len(t, before, 3, "original map unchanged") + assert.Len(t, before, 5, "original map unchanged") assert.Equal(t, map[string]interface{}{ "a": map[string]interface{}{ "b": 1, + "c": map[string]interface{}{ + "d": 2, + }, }, - "ab": 3, + "ab": 4, + "abb": 5, }, after) }) }