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

Function TestEnv

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

Source from the content-addressed store, hash-verified

604}
605
606func TestEnv(t *testing.T) {
607 v := New()
608 v.SetConfigType("json")
609 // Read the JSON data into Viper configuration v.config
610 require.NoError(t, v.ReadConfig(bytes.NewBuffer(jsonExample)), "Error reading json data")
611
612 v.BindEnv("id")
613 v.BindEnv("f", "FOOD", "OLD_FOOD")
614
615 t.Setenv("ID", "13")
616 t.Setenv("FOOD", "apple")
617 t.Setenv("OLD_FOOD", "banana")
618 t.Setenv("NAME", "crunk")
619
620 assert.Equal(t, "13", v.Get("id"))
621 assert.Equal(t, "apple", v.Get("f"))
622 assert.Equal(t, "Cake", v.Get("name"))
623
624 v.AutomaticEnv()
625
626 assert.Equal(t, "crunk", v.Get("name"))
627}
628
629func TestMultipleEnv(t *testing.T) {
630 v := New()

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected