From 63a39fe60573719860c605f9f3624634f0d4adff Mon Sep 17 00:00:00 2001 From: Benoit Masson Date: Thu, 29 Sep 2016 15:52:01 +0200 Subject: [PATCH] Tests: add a test for checking precedence of dot-containing keys. if config["foo"]["bar"] and config["foo.bar"] coexist, the latter value should be used (as described in README). --- viper_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/viper_test.go b/viper_test.go index aa03650..77fc987 100644 --- a/viper_test.go +++ b/viper_test.go @@ -923,6 +923,17 @@ func TestShadowedNestedValue(t *testing.T) { assert.Equal(t, polyester, GetString("clothing.shirt")) } +func TestDotParameter(t *testing.T) { + initJSON() + // shoud take precedence over batters defined in jsonExample + r := bytes.NewReader([]byte(`{ "batters.batter": [ { "type": "Small" } ] }`)) + unmarshalReader(r, v.config) + + actual := Get("batters.batter") + expected := []interface{}{map[string]interface{}{"type": "Small"}} + assert.Equal(t, expected, actual) +} + func TestGetBool(t *testing.T) { key := "BooleanKey" v = New()