-
Notifications
You must be signed in to change notification settings - Fork 3
/
float32_slice_test.go
80 lines (58 loc) · 1.72 KB
/
float32_slice_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
package env_test
import (
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestGetFloat32Slice(t *testing.T) {
t.Run("GetAbsentFloat32SliceWithDefault", func(t *testing.T) {
def := []float32{21.2, 22.3}
res := env.GetFloat32Slice("V1", def)
assert.Equal(t, def, res)
})
t.Run("GetValidFloat32SliceWithDefault", func(t *testing.T) {
def := []float32{21.2, 22.3}
expected := []float32{31.02, 32.33, 33.33}
t.Setenv("V1", "31.02,32.33,33.33")
res := env.GetFloat32Slice("V1", def)
assert.Equal(t, expected, res)
})
t.Run("GetInvalidFloat32SliceWithDefault", func(t *testing.T) {
def := []float32{21.2, 22.3}
t.Setenv("V1", "1.2,2.3,Three")
res := env.GetFloat32Slice("V1", def)
assert.Equal(t, def, res)
})
t.Run("GetEmptyFloat32SliceWithDefault", func(t *testing.T) {
def := []float32{21.2, 22.3}
expected := make([]float32, 0)
t.Setenv("V1", "")
res := env.GetFloat32Slice("V1", def)
assert.Equal(t, expected, res)
})
}
func TestMustGetFloat32Slice(t *testing.T) {
t.Run("MustGetAbsentFloat32Slice", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat32Slice("V1")
})
})
t.Run("MustGetValidFloat32Slice", func(t *testing.T) {
expected := []float32{31.02, 32.33, 33.33}
t.Setenv("V1", "31.02,32.33,33.33")
res := env.MustGetFloat32Slice("V1")
assert.Equal(t, expected, res)
})
t.Run("MustGetInvalidFloat32Slice", func(t *testing.T) {
t.Setenv("V1", "1.2,2.3,Three")
assert.Panics(t, func() {
env.MustGetFloat32Slice("V1")
})
})
t.Run("MustGetEmptyFloat32Slice", func(t *testing.T) {
expected := make([]float32, 0)
t.Setenv("V1", "")
res := env.MustGetFloat32Slice("V1")
assert.Equal(t, expected, res)
})
}