From e6b18b458a9e1de1230a53efe6dd65b724230833 Mon Sep 17 00:00:00 2001 From: Benoit Masson Date: Sun, 23 Oct 2016 22:00:22 +0200 Subject: [PATCH] Added: test for BindEnv() and AllKeys() To make sure AllSettings() and Unmarshal() will consider environment variables added with BindEnv(). --- viper_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/viper_test.go b/viper_test.go index ab1f834..83dbac4 100644 --- a/viper_test.go +++ b/viper_test.go @@ -445,6 +445,23 @@ func TestAllKeys(t *testing.T) { assert.Equal(t, all, AllSettings()) } +func TestAllKeysWithEnv(t *testing.T) { + v := New() + + // bind and define environment variables (including a nested one) + v.BindEnv("id") + v.BindEnv("foo.bar") + v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) + os.Setenv("ID", "13") + os.Setenv("FOO_BAR", "baz") + + expectedKeys := sort.StringSlice{"id", "foo.bar"} + expectedKeys.Sort() + keys := sort.StringSlice(v.AllKeys()) + keys.Sort() + assert.Equal(t, expectedKeys, keys) +} + func TestAliasesOfAliases(t *testing.T) { Set("Title", "Checking Case") RegisterAlias("Foo", "Bar")