Skip to content

Commit

Permalink
Make the map in MergeConfigMap case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Dec 7, 2018
1 parent 41cd1c3 commit 6d33b5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions viper.go
Expand Up @@ -1267,11 +1267,13 @@ func (v *Viper) MergeConfig(in io.Reader) error {
}

// MergeConfigMap merges the configuration from the map given with an existing config.
// Note that the map given may be modified.
func MergeConfigMap(cfg map[string]interface{}) error { return v.MergeConfigMap(cfg) }
func (v *Viper) MergeConfigMap(cfg map[string]interface{}) error {
if v.config == nil {
v.config = make(map[string]interface{})
}
insensitiviseMap(cfg)
mergeMaps(cfg, v.config, nil)
return nil
}
Expand Down
11 changes: 9 additions & 2 deletions viper_test.go
Expand Up @@ -1252,15 +1252,22 @@ func TestMergeConfigMap(t *testing.T) {
assert(37890)

update := map[string]interface{}{
"hello": map[string]interface{}{
"pop": 1234,
"Hello": map[string]interface{}{
"Pop": 1234,
},
"World": map[interface{}]interface{}{
"Rock": 345,
},
}

if err := v.MergeConfigMap(update); err != nil {
t.Fatal(err)
}

if rock := v.GetInt("world.rock"); rock != 345 {
t.Fatal("Got rock:", rock)
}

assert(1234)

}
Expand Down

0 comments on commit 6d33b5a

Please sign in to comment.