Skip to content

Commit

Permalink
Added test case for merging configs, where target is null, and source…
Browse files Browse the repository at this point in the history
… is not null
  • Loading branch information
illarion authored and sagikazarmark committed Jan 11, 2022
1 parent 0353c6e commit 97664ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion viper.go
Expand Up @@ -1808,7 +1808,7 @@ func mergeMaps(
v.logger.Trace("merging maps")
tsv, ok := sv.(map[string]interface{})
if !ok {
jww.ERROR.Printf(
v.logger.Error(
"Could not cast sv to map[string]interface{}; key=%s, st=%v, tt=%v, sv=%v, tv=%v",
sk, svType, tvType, sv, tv)
continue
Expand Down
6 changes: 6 additions & 0 deletions viper_test.go
Expand Up @@ -1915,6 +1915,7 @@ fu: bar
var jsonMergeExampleTgt = []byte(`
{
"hello": {
"foo": null,
"pop": 123456
}
}
Expand All @@ -1923,6 +1924,7 @@ var jsonMergeExampleTgt = []byte(`
var jsonMergeExampleSrc = []byte(`
{
"hello": {
"foo": "foo str",
"pop": "pop str"
}
}
Expand Down Expand Up @@ -2014,6 +2016,10 @@ func TestMergeConfigOverrideType(t *testing.T) {
if pop := v.GetString("hello.pop"); pop != "pop str" {
t.Fatalf("pop != \"pop str\", = %s", pop)
}

if foo := v.GetString("hello.foo"); foo != "foo str" {
t.Fatalf("foo != \"foo str\", = %s", foo)
}
}

func TestMergeConfigNoMerge(t *testing.T) {
Expand Down

0 comments on commit 97664ba

Please sign in to comment.