-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfloat32_test.go
59 lines (43 loc) · 1.13 KB
/
float32_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
package env_test
import (
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestGetFloat32(t *testing.T) {
t.Run("GetAbsentFloat32WithDefault", func(t *testing.T) {
def := float32(12.5)
res := env.GetFloat32("V1", def)
assert.InDelta(t, def, res, 0)
})
t.Run("GetInvalidFloat32WithDefault", func(t *testing.T) {
t.Setenv("V1", "invalid")
def := float32(12.5)
res := env.GetFloat32("V1", def)
assert.InDelta(t, def, res, 0)
})
t.Run("GetValidFloat32WithDefault", func(t *testing.T) {
def := float32(12.5)
t.Setenv("V1", "14.5")
res := env.GetFloat32("V1", def)
assert.InDelta(t, float32(14.5), res, 0)
})
}
func TestMustGetFloat32(t *testing.T) {
t.Run("MustGetAbsentFloat32", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetFloat32("V1")
})
})
t.Run("MustGetInvalidFloat32", func(t *testing.T) {
assert.Panics(t, func() {
t.Setenv("V1", "invalid")
env.MustGetFloat32("V1")
})
})
t.Run("MustGetValidFloat32", func(t *testing.T) {
t.Setenv("V1", "14.5")
res := env.MustGetFloat32("V1")
assert.InDelta(t, float32(14.5), res, 0)
})
}