From 6d33b5a963d922d182c91e8a1c88d81fd150cfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 7 Dec 2018 11:02:11 +0100 Subject: [PATCH] Make the map in MergeConfigMap case insensitive --- viper.go | 2 ++ viper_test.go | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/viper.go b/viper.go index ca1a2de11..cee37b216 100644 --- a/viper.go +++ b/viper.go @@ -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 } diff --git a/viper_test.go b/viper_test.go index 94bf5e4de..f4263d386 100644 --- a/viper_test.go +++ b/viper_test.go @@ -1252,8 +1252,11 @@ 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, }, } @@ -1261,6 +1264,10 @@ func TestMergeConfigMap(t *testing.T) { t.Fatal(err) } + if rock := v.GetInt("world.rock"); rock != 345 { + t.Fatal("Got rock:", rock) + } + assert(1234) }