-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_test.go
More file actions
76 lines (71 loc) · 1.43 KB
/
Copy pathstring_test.go
File metadata and controls
76 lines (71 loc) · 1.43 KB
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
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"},
},
{
name: "env empty string, def empty",
envKey: "SOME_ENV",
envVal: "",
want: []string{},
},
{
name: "env empty string, def not empty",
envKey: "SOME_ENV",
envVal: "",
def: []string{"d", "e", "f"},
want: []string{"d", "e", "f"},
},
{
name: "trims spaces and drops empty elements",
envKey: "SOME_ENV",
envVal: " a , b , ,c,",
want: []string{"a", "b", "c"},
},
{
name: "leading and trailing commas",
envKey: "SOME_ENV",
envVal: ",a,,b,",
want: []string{"a", "b"},
},
}
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)
})
}
}