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:
Joe Buck 2016-02-18 21:27:02 -08:00
parent 13a79f2a27
commit e8036e1a24

View file

@ -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) {
initJSON()