(t *testing.T)
| 604 | } |
| 605 | |
| 606 | func 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 | |
| 629 | func TestMultipleEnv(t *testing.T) { |
| 630 | v := New() |
nothing calls this directly
no test coverage detected