mirror of
https://github.com/spf13/viper
synced 2025-05-06 12:17:18 +00:00
Added: test for BindEnv() and AllKeys()
To make sure AllSettings() and Unmarshal() will consider environment variables added with BindEnv().
This commit is contained in:
parent
50515b700e
commit
e6b18b458a
1 changed files with 17 additions and 0 deletions
|
@ -445,6 +445,23 @@ func TestAllKeys(t *testing.T) {
|
||||||
assert.Equal(t, all, AllSettings())
|
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) {
|
func TestAliasesOfAliases(t *testing.T) {
|
||||||
Set("Title", "Checking Case")
|
Set("Title", "Checking Case")
|
||||||
RegisterAlias("Foo", "Bar")
|
RegisterAlias("Foo", "Bar")
|
||||||
|
|
Loading…
Add table
Reference in a new issue