mirror of
https://github.com/spf13/viper
synced 2024-12-22 19:47:01 +00:00
Added test case for merging configs, where target is null, and source is not null
This commit is contained in:
parent
0353c6ea50
commit
97664ba020
2 changed files with 7 additions and 1 deletions
2
viper.go
2
viper.go
|
@ -1808,7 +1808,7 @@ func mergeMaps(
|
||||||
v.logger.Trace("merging maps")
|
v.logger.Trace("merging maps")
|
||||||
tsv, ok := sv.(map[string]interface{})
|
tsv, ok := sv.(map[string]interface{})
|
||||||
if !ok {
|
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",
|
"Could not cast sv to map[string]interface{}; key=%s, st=%v, tt=%v, sv=%v, tv=%v",
|
||||||
sk, svType, tvType, sv, tv)
|
sk, svType, tvType, sv, tv)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1915,6 +1915,7 @@ fu: bar
|
||||||
var jsonMergeExampleTgt = []byte(`
|
var jsonMergeExampleTgt = []byte(`
|
||||||
{
|
{
|
||||||
"hello": {
|
"hello": {
|
||||||
|
"foo": null,
|
||||||
"pop": 123456
|
"pop": 123456
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1923,6 +1924,7 @@ var jsonMergeExampleTgt = []byte(`
|
||||||
var jsonMergeExampleSrc = []byte(`
|
var jsonMergeExampleSrc = []byte(`
|
||||||
{
|
{
|
||||||
"hello": {
|
"hello": {
|
||||||
|
"foo": "foo str",
|
||||||
"pop": "pop str"
|
"pop": "pop str"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2014,6 +2016,10 @@ func TestMergeConfigOverrideType(t *testing.T) {
|
||||||
if pop := v.GetString("hello.pop"); pop != "pop str" {
|
if pop := v.GetString("hello.pop"); pop != "pop str" {
|
||||||
t.Fatalf("pop != \"pop str\", = %s", pop)
|
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) {
|
func TestMergeConfigNoMerge(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue