Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not delete expr tag tmpl values. Fixes #6909 #6921

Merged
merged 1 commit into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion util/expand/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
18 changes: 12 additions & 6 deletions util/expand/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistake here? Either remove the loop + comments or change back to i < 100? @alexec

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops.

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)
})
}
Expand Down