-
Notifications
You must be signed in to change notification settings - Fork 8
/
env_test.go
61 lines (45 loc) · 1.2 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package giphy
import (
"os"
"strconv"
"testing"
)
func TestEnv(t *testing.T) {
in, out := "baz", "bar"
os.Setenv("ENVSTR", out)
if got := Env("ENVSTR", in); got != out {
t.Errorf(`String("ENVSTR", "%v") = %v, want %v`, in, got, out)
}
}
func TestEnvDefault(t *testing.T) {
in, out := "baz", "baz"
if got := Env("ENVSTR_DEFAULT", in); got != out {
t.Errorf(`String("ENVSTR_DEFAULT", "%v") = %v, want %v`, in, got, out)
}
}
func TestEnvBool(t *testing.T) {
in, out := false, true
os.Setenv("ENVBOOL", "true")
if got := EnvBool("ENVBOOL", in); got != out {
t.Errorf(`Bool("ENVBOOL", %v) = %v, want %v`, in, got, out)
}
}
func TestEnvBoolDefault(t *testing.T) {
in, out := true, true
if got := EnvBool("ENVBOOL_DEFAULT", in); got != out {
t.Errorf(`Bool("ENVBOOL_DEFAULT", %v) = %v, want %v`, in, got, out)
}
}
func TestEnvInt(t *testing.T) {
in, out := 1, 2
os.Setenv("ENVINT", strconv.Itoa(out))
if got := EnvInt("ENVINT", in); got != out {
t.Errorf(`Int("ENVINT", %v) = %v, want %v`, in, got, out)
}
}
func TestEnvIntDefault(t *testing.T) {
in, out := 3, 3
if got := EnvInt("ENVINT_DEFAULT", in); got != out {
t.Errorf(`Int("ENVINT_DEFAULT", %v) = %v, want %v`, in, got, out)
}
}