-
Notifications
You must be signed in to change notification settings - Fork 3
/
string_slice_test.go
58 lines (45 loc) · 1.35 KB
/
string_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
package env_test
import (
"strings"
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestGetStringSlice(t *testing.T) {
def := []string{"foo", "bar"}
t.Run("GetAbsentStringSliceWithDefault", func(t *testing.T) {
res := env.GetStringSlice("V1", def)
assert.Equal(t, def, res)
})
t.Run("GetValidStringSliceWithDefault", func(t *testing.T) {
expected := []string{"foo", "bar", "baz"}
t.Setenv("V1", strings.Join(expected, ","))
res := env.GetStringSlice("V1", def)
assert.Equal(t, expected, res)
})
t.Run("GetEmptyStringSliceWithDefault", func(t *testing.T) {
expected := make([]string, 0)
t.Setenv("V1", strings.Join(expected, ","))
res := env.GetStringSlice("V1", def)
assert.Equal(t, expected, res)
})
}
func TestMustGetStringSlice(t *testing.T) {
t.Run("MustGetAbsentStringSlice", func(t *testing.T) {
assert.Panics(t, func() {
env.MustGetStringSlice("V1")
})
})
t.Run("MustGetValidStringSlice", func(t *testing.T) {
expected := []string{"foo", "bar", "baz"}
t.Setenv("V1", strings.Join(expected, ","))
res := env.MustGetStringSlice("V1")
assert.Equal(t, expected, res)
})
t.Run("MustGetEmptyStringSlice", func(t *testing.T) {
expected := make([]string, 0)
t.Setenv("V1", strings.Join(expected, ","))
res := env.MustGetStringSlice("V1")
assert.Equal(t, expected, res)
})
}