-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring_test.go
51 lines (46 loc) · 915 Bytes
/
string_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
package getenv
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStringSlice(t *testing.T) {
tests := []struct {
name string
def []string
want []string
envKey string
envVal string
}{
{
name: "empty",
want: []string{},
},
{
name: "val empty, def not empty",
def: []string{"a", "b", "c"},
want: []string{"a", "b", "c"},
},
{
name: "val not empty, def empty",
envKey: "SOME_ENV",
envVal: "a,b,c",
want: []string{"a", "b", "c"},
},
{
name: "val not empty, def not empty",
envKey: "SOME_ENV",
envVal: "a,b,c",
def: []string{"d", "e", "f"},
want: []string{"a", "b", "c"},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.envKey != "" {
t.Setenv(test.envKey, test.envVal)
}
got := StringSlice(test.envKey, test.def)
assert.Equal(t, test.want, got)
})
}
}