MCPcopy
hub / github.com/spf13/viper / TestEnvSubConfig

Function TestEnvSubConfig

viper_test.go:734–751  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

732}
733
734func TestEnvSubConfig(t *testing.T) {
735 v := New()
736 v.SetConfigType("yaml")
737 // Read the YAML data into Viper configuration v.config
738 require.NoError(t, v.ReadConfig(bytes.NewBuffer(yamlExample)), "Error reading json data")
739 v.AutomaticEnv()
740 v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
741
742 t.Setenv("CLOTHING_PANTS_SIZE", "small")
743 subv := v.Sub("clothing").Sub("pants")
744 assert.Equal(t, "small", subv.Get("size"))
745
746 // again with EnvPrefix
747 v.SetEnvPrefix("foo") // will be uppercased automatically
748 subWithPrefix := v.Sub("clothing").Sub("pants")
749 t.Setenv("FOO_CLOTHING_PANTS_SIZE", "large")
750 assert.Equal(t, "large", subWithPrefix.Get("size"))
751}
752
753func TestAllKeys(t *testing.T) {
754 v := New()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.85
SetConfigTypeMethod · 0.80
ReadConfigMethod · 0.80
AutomaticEnvMethod · 0.80
SetEnvKeyReplacerMethod · 0.80
SubMethod · 0.80
SetEnvPrefixMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected