-
Notifications
You must be signed in to change notification settings - Fork 3
/
bool_test.go
86 lines (64 loc) · 1.63 KB
/
bool_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
package env_test
import (
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestGetBool(t *testing.T) {
t.Run("GetAbsentBoolWithDefault", func(t *testing.T) {
res := env.GetBool("V1", true)
assert.True(t, res)
})
t.Run("GetPresentBoolWithDefault", func(t *testing.T) {
t.Setenv("V1", "false")
res := env.GetBool("V1", true)
assert.False(t, res)
})
t.Run("GetZeroAsBoolWithDefault", func(t *testing.T) {
t.Setenv("V1", "0")
res := env.GetBool("V1", true)
assert.False(t, res)
})
t.Run("GetTrueStringAsBoolWithDefault", func(t *testing.T) {
t.Setenv("V1", "true")
res := env.GetBool("V1", false)
assert.True(t, res)
})
t.Run("GetEmptyAsBoolWithDefault", func(t *testing.T) {
t.Setenv("V1", "")
res := env.GetBool("V1", false)
assert.True(t, res)
})
t.Run("GetOneAsBoolWithDefault", func(t *testing.T) {
t.Setenv("V1", "1")
res := env.GetBool("V1", false)
assert.True(t, res)
})
}
func TestMustGetBool(t *testing.T) {
t.Run("MustGetAbsentBool", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetBool("V1")
})
})
t.Run("MustGetFalseStringAsBool", func(t *testing.T) {
t.Setenv("V1", "false")
res := env.MustGetBool("V1")
assert.False(t, res)
})
t.Run("MustGetZeroAsBool", func(t *testing.T) {
t.Setenv("V1", "0")
res := env.MustGetBool("V1")
assert.False(t, res)
})
t.Run("MustGetTrueStringAsBool", func(t *testing.T) {
t.Setenv("V1", "true")
res := env.MustGetBool("V1")
assert.True(t, res)
})
t.Run("MustGetOneAsBool", func(t *testing.T) {
t.Setenv("V1", "1")
res := env.MustGetBool("V1")
assert.True(t, res)
})
}