-
Notifications
You must be signed in to change notification settings - Fork 3
/
env_test.go
93 lines (63 loc) · 1.58 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package env_test
import (
"fmt"
"os"
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestEnv_String(t *testing.T) {
v := "testing"
t.Setenv("ENV", v)
res := env.Environment()
assert.EqualValues(t, v, res)
}
func ExampleEnvironment() {
_ = os.Setenv("ENV", "testing")
fmt.Println(env.Environment())
// Output: testing
}
func TestEnvironment(t *testing.T) {
assert.Zero(t, env.Environment())
t.Setenv("ENV", "testing")
assert.Equal(t, env.Testing, env.Environment())
}
func TestIs(t *testing.T) {
t.Run("Single Env", func(t *testing.T) {
t.Setenv("ENV", "testing")
assert.True(t, env.Is(env.Testing))
})
t.Run("Multiple Envs", func(t *testing.T) {
t.Setenv("ENV", "testing")
assert.True(t, env.Is(env.Development, env.Testing))
})
t.Run("Multiple Envs", func(t *testing.T) {
t.Setenv("ENV", "testing")
assert.True(t, env.Is(env.Testing, env.Development))
})
}
func ExampleIs() {
_ = os.Setenv("ENV", "testing")
fmt.Println(env.Is(env.Testing))
// Output: true
}
func TestIsDevelopment(t *testing.T) {
assert.False(t, env.IsDevelopment())
t.Setenv("ENV", "development")
assert.True(t, env.IsDevelopment())
}
func TestIsTesting(t *testing.T) {
assert.False(t, env.IsTesting())
t.Setenv("ENV", "testing")
assert.True(t, env.IsTesting())
}
func TestIsStaging(t *testing.T) {
assert.False(t, env.IsStaging())
t.Setenv("ENV", "staging")
assert.True(t, env.IsStaging())
}
func TestIsProduction(t *testing.T) {
assert.False(t, env.IsProduction())
t.Setenv("ENV", "production")
assert.True(t, env.IsProduction())
}