-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing issue #139 as expected by Sprig's merge template function as …
…used in Helm
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package mergo | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIssue139(t *testing.T) { | ||
srcs := []map[string]interface{}{ | ||
{ | ||
"h": 10, | ||
"i": "i", | ||
"j": "j", | ||
}, | ||
{ | ||
"a": 1, | ||
"b": 2, | ||
"d": map[string]interface{}{ | ||
"e": "four", | ||
}, | ||
"g": []int{6, 7}, | ||
"i": "aye", | ||
"j": "jay", | ||
"k": map[string]interface{}{ | ||
"l": false, | ||
}, | ||
}, | ||
} | ||
dst := map[string]interface{}{ | ||
"a": "one", | ||
"c": 3, | ||
"d": map[string]interface{}{ | ||
"f": 5, | ||
}, | ||
"g": []int{8, 9}, | ||
"i": "eye", | ||
"k": map[string]interface{}{ | ||
"l": true, | ||
}, | ||
} | ||
|
||
for _, src := range srcs { | ||
if err := Merge(&dst, src); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
expected := map[string]interface{}{ | ||
"a": "one", // key overridden | ||
"b": 2, // merged from src1 | ||
"c": 3, // merged from dst | ||
"d": map[string]interface{}{ // deep merge | ||
"e": "four", | ||
"f": 5, | ||
}, | ||
"g": []int{8, 9}, // overridden - arrays are not merged | ||
"h": 10, // merged from src2 | ||
"i": "eye", // overridden twice | ||
"j": "jay", // overridden and merged | ||
"k": map[string]interface{}{ | ||
"l": true, // overridden | ||
}, | ||
} | ||
assert.Equal(t, expected, dst) | ||
} |