-
Notifications
You must be signed in to change notification settings - Fork 3
/
uint32_test.go
53 lines (41 loc) · 1.03 KB
/
uint32_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
package env_test
import (
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestGetUint32(t *testing.T) {
def := uint32(12)
t.Run("GetAbsentUInt32WithDefault", func(t *testing.T) {
res := env.GetUint32("V1", def)
assert.Equal(t, def, res)
})
t.Run("GetInvalidUInt32WithDefault", func(t *testing.T) {
t.Setenv("V1", "invalid")
res := env.GetUint32("V1", def)
assert.Equal(t, def, res)
})
t.Run("GetValidUInt32WithDefault", func(t *testing.T) {
t.Setenv("V1", "14")
res := env.GetUint32("V1", def)
assert.Equal(t, uint32(14), res)
})
}
func TestMustGetUint32(t *testing.T) {
t.Run("MustGetAbsentUInt32", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetUint32("V1")
})
})
t.Run("MustGetInvalidUInt32", func(t *testing.T) {
assert.Panics(t, func() {
t.Setenv("V1", "invalid")
env.MustGetUint32("V1")
})
})
t.Run("MustGetValidUInt32", func(t *testing.T) {
t.Setenv("V1", "14")
res := env.MustGetUint32("V1")
assert.Equal(t, uint32(14), res)
})
}