| 1 | package gostub |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/stretchr/testify/assert" |
| 8 | ) |
| 9 | |
| 10 | func TestStubEnv(t *testing.T) { |
| 11 | os.Setenv("GOSTUB_T1", "V1") |
| 12 | os.Setenv("GOSTUB_T2", "V2") |
| 13 | os.Unsetenv("GOSTUB_NONE") |
| 14 | |
| 15 | stubs := New() |
| 16 | |
| 17 | stubs.SetEnv("GOSTUB_NONE", "a") |
| 18 | stubs.SetEnv("GOSTUB_T1", "1") |
| 19 | stubs.SetEnv("GOSTUB_T1", "2") |
| 20 | stubs.SetEnv("GOSTUB_T1", "3") |
| 21 | stubs.SetEnv("GOSTUB_T2", "4") |
| 22 | stubs.UnsetEnv("GOSTUB_T2") |
| 23 | |
| 24 | assert.Equal(t, "3", os.Getenv("GOSTUB_T1"), "Wrong value for T1") |
| 25 | assert.Equal(t, "", os.Getenv("GOSTUB_T2"), "Wrong value for T2") |
| 26 | assert.Equal(t, "a", os.Getenv("GOSTUB_NONE"), "Wrong value for NONE") |
| 27 | stubs.Reset() |
| 28 | |
| 29 | _, ok := os.LookupEnv("GOSTUB_NONE") |
| 30 | assert.False(t, ok, "NONE should be unset") |
| 31 | |
| 32 | assert.Equal(t, "V1", os.Getenv("GOSTUB_T1"), "Wrong reset value for T1") |
| 33 | assert.Equal(t, "V2", os.Getenv("GOSTUB_T2"), "Wrong reset value for T2") |
| 34 | } |