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