mirror of
https://github.com/spf13/viper
synced 2024-12-23 03:57:01 +00:00
Add test for parsing nested keys from environment variables
Add a test where an environment variable with a nested key is set and then retrieved. The nested key uses an underscore in place of a dot to indicate the key hierarchy.
This commit is contained in:
parent
13a79f2a27
commit
e8036e1a24
1 changed files with 24 additions and 0 deletions
|
@ -371,6 +371,30 @@ func TestEnv(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnvNestedKeys(t *testing.T) {
|
||||||
|
initJSON()
|
||||||
|
|
||||||
|
BindEnv("id")
|
||||||
|
BindEnv("f", "FOOD")
|
||||||
|
|
||||||
|
// Validate the default value
|
||||||
|
assert.Equal(t, "fancy", Get("icing.type"))
|
||||||
|
|
||||||
|
os.Setenv("ID", "13")
|
||||||
|
os.Setenv("FOOD", "apple")
|
||||||
|
os.Setenv("NAME", "crunk")
|
||||||
|
os.Setenv("ICING_TYPE", "plain")
|
||||||
|
|
||||||
|
assert.Equal(t, "13", Get("id"))
|
||||||
|
assert.Equal(t, "apple", Get("f"))
|
||||||
|
assert.Equal(t, "Cake", Get("name"))
|
||||||
|
|
||||||
|
AutomaticEnv()
|
||||||
|
|
||||||
|
assert.Equal(t, "plain", Get("icing.type"))
|
||||||
|
assert.Equal(t, "crunk", Get("name"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestEnvPrefix(t *testing.T) {
|
func TestEnvPrefix(t *testing.T) {
|
||||||
initJSON()
|
initJSON()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue