(t *testing.T)
| 672 | } |
| 673 | |
| 674 | func 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 | |
| 697 | func TestAutoEnv(t *testing.T) { |
| 698 | v := New() |
nothing calls this directly
no test coverage detected