-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude nil entries from values for helm charts (#1845)
* Exclude nil entries from values * Changelog * Fix IsNil handling
- Loading branch information
Vivek Lakshmanan
authored
Dec 22, 2021
1 parent
81b4ff2
commit cb2803c
Showing
3 changed files
with
155 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package provider | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func Test_MergeMaps(t *testing.T) { | ||
m := map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"d": []interface{}{ | ||
"1", "2", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
override := map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"d": []interface{}{ | ||
"3", "4", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range []struct { | ||
name string | ||
dest map[string]interface{} | ||
src map[string]interface{} | ||
expected map[string]interface{} | ||
}{ | ||
{ | ||
name: "Precedence", | ||
dest: m, | ||
src: override, | ||
expected: override, // Expect the override to take precedence | ||
}, | ||
{ | ||
name: "Merge maps", | ||
dest: m, | ||
src: map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"c": []interface{}{ | ||
"3", "4", | ||
}, | ||
"f": true, | ||
}, | ||
}, | ||
}, | ||
expected: map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"d": []interface{}{ | ||
"1", "2", | ||
}, | ||
"c": []interface{}{ | ||
"3", "4", | ||
}, | ||
"f": true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Dest Has Nil Values", | ||
dest: m, | ||
src: map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"c": interface{}(nil), | ||
"e": (*interface{})(nil), | ||
}, | ||
}, | ||
}, | ||
expected: map[string]interface{}{ | ||
"a": map[string]interface{}{ | ||
"b": map[string]interface{}{ | ||
"d": []interface{}{ | ||
"1", "2", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} { | ||
t.Run(test.name, func(t *testing.T) { | ||
merged, err := mergeMaps(test.dest, test.src) | ||
require.NoError(t, err) | ||
assert.Equal(t, test.expected, merged) | ||
}) | ||
} | ||
} |