-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_test.go
44 lines (36 loc) · 940 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
35
36
37
38
39
40
41
42
43
44
package simular
import (
"net/http"
"os"
"testing"
)
func TestEnv(t *testing.T) {
DeactivateAndReset()
orig := os.Getenv(envVarName)
// put it in an enabled state
if err := os.Setenv(envVarName, ""); err != nil {
t.Fatal(err)
} else if Disabled() {
t.Fatal("expected not to be disabled")
}
// make sure an activation works
Activate()
if http.DefaultTransport != mockTransport {
t.Fatal("expected http.DefaultTransport to be our mockTransport")
}
Deactivate()
if err := os.Setenv(envVarName, "1"); err != nil {
t.Fatal(err)
} else if !Disabled() {
t.Fatal("expected to be disabled")
}
// make sure activation doesn't work
Activate()
if http.DefaultTransport == mockTransport {
t.Fatal("expected http.DefaultTransport to not be our mockTransport")
}
Deactivate()
if err := os.Setenv(envVarName, orig); err != nil {
t.Fatalf("could not reset %s to it's original value '%s'", envVarName, orig)
}
}