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

Function TestEnvPrefix

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

Source from the content-addressed store, hash-verified

672}
673
674func TestEnvPrefix(t *testing.T) {
675 v := New()
676 v.SetConfigType("json")
677 // Read the JSON data into Viper configuration v.config
678 require.NoError(t, v.ReadConfig(bytes.NewBuffer(jsonExample)), "Error reading json data")
679
680 v.SetEnvPrefix("foo") // will be uppercased automatically
681 v.BindEnv("id")
682 v.BindEnv("f", "FOOD") // not using prefix
683
684 t.Setenv("FOO_ID", "13")
685 t.Setenv("FOOD", "apple")
686 t.Setenv("FOO_NAME", "crunk")
687
688 assert.Equal(t, "13", v.Get("id"))
689 assert.Equal(t, "apple", v.Get("f"))
690 assert.Equal(t, "Cake", v.Get("name"))
691
692 v.AutomaticEnv()
693
694 assert.Equal(t, "crunk", v.Get("name"))
695}
696
697func TestAutoEnv(t *testing.T) {
698 v := New()

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
SetConfigTypeMethod · 0.80
ReadConfigMethod · 0.80
SetEnvPrefixMethod · 0.80
BindEnvMethod · 0.80
AutomaticEnvMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected