Skip to content

Commit 2a0f44a

Browse files
authored
Merge pull request #14 from ieee0824/string-slice
add test
2 parents e254cd1 + 67e1858 commit 2a0f44a

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

.go-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.16.4
1+
1.21.0

go.sum

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
9+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
10+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
11+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
12+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
14+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
16+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

string_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package getenv
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestStringSlice(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
def []string
13+
want []string
14+
envKey string
15+
envVal string
16+
}{
17+
{
18+
name: "empty",
19+
want: []string{},
20+
},
21+
{
22+
name: "val empty, def not empty",
23+
def: []string{"a", "b", "c"},
24+
want: []string{"a", "b", "c"},
25+
},
26+
{
27+
name: "val not empty, def empty",
28+
envKey: "SOME_ENV",
29+
envVal: "a,b,c",
30+
want: []string{"a", "b", "c"},
31+
},
32+
{
33+
name: "val not empty, def not empty",
34+
envKey: "SOME_ENV",
35+
envVal: "a,b,c",
36+
def: []string{"d", "e", "f"},
37+
want: []string{"a", "b", "c"},
38+
},
39+
}
40+
41+
for _, test := range tests {
42+
t.Run(test.name, func(t *testing.T) {
43+
if test.envKey != "" {
44+
t.Setenv(test.envKey, test.envVal)
45+
}
46+
47+
got := StringSlice(test.envKey, test.def)
48+
assert.Equal(t, test.want, got)
49+
})
50+
}
51+
}

0 commit comments

Comments
 (0)