Skip to content

Commit

Permalink
Merge pull request #14 from ieee0824/string-slice
Browse files Browse the repository at this point in the history
add test
  • Loading branch information
ieee0824 authored Dec 19, 2023
2 parents e254cd1 + 67e1858 commit 2a0f44a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.16.4
1.21.0
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
51 changes: 51 additions & 0 deletions string_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
})
}
}

0 comments on commit 2a0f44a

Please sign in to comment.