Skip to content

Commit

Permalink
fix structuredmerge filterintent to cleanup nested empty maps
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jun 30, 2022
1 parent 89da95f commit f042df6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func filterIntent(ctx *filterIntentInput) bool {
// Ensure we are not leaving empty maps around.
if v, ok := fieldCtx.value.(map[string]interface{}); ok && len(v) == 0 {
delete(value, field)
gotDeletions = true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ func Test_filterIgnoredPaths(t *testing.T) {
// we are filtering out spec.foo and then spec given that it is an empty map
},
},
{
name: "Cleanup emptynested maps",
ctx: &filterIntentInput{
path: contract.Path{},
value: map[string]interface{}{
"spec": map[string]interface{}{
"bar": map[string]interface{}{
"foo": "123",
},
},
},
shouldFilter: isIgnorePath(
[]contract.Path{
{"spec", "bar", "foo"},
},
),
},
wantValue: map[string]interface{}{
// we are filtering out spec.bar.foo and then spec given that it is an empty map
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit f042df6

Please sign in to comment.