Skip to content

Commit

Permalink
Unit tests, go mod tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Aug 10, 2023
1 parent b31ebca commit 2dc1edb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/flex/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func ExpandStringList(configured []interface{}) []*string {
}

// ExpandStringListEmpty the result of flatmap. Expand for an array of strings
// and returns a []*string. Empty strings are NOT skipped.
// and returns a []*string. Adds an empty element for every nil or uncastable.
func ExpandStringListEmpty(configured []interface{}) []*string {
vs := make([]*string, 0, len(configured))
for _, v := range configured {
Expand Down
31 changes: 31 additions & 0 deletions internal/flex/flex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,37 @@ func TestExpandStringList(t *testing.T) {
}
}

func TestExpandStringListEmpty(t *testing.T) {
t.Parallel()

testCases := []struct {
configured []interface{}
want []*string
}{
{
configured: []interface{}{"abc", "xyz123"},
want: []*string{aws.String("abc"), aws.String("xyz123")},
},
{
configured: []interface{}{"abc", 123, "xyz123"},
want: []*string{aws.String("abc"), aws.String(""), aws.String("xyz123")},
},
{
configured: []interface{}{"foo", "bar", "", "baz"},
want: []*string{aws.String("foo"), aws.String("bar"), aws.String(""), aws.String("baz")},
},
{
configured: []interface{}{"foo", "bar", nil, "baz"},
want: []*string{aws.String("foo"), aws.String("bar"), aws.String(""), aws.String("baz")},
},
}
for _, testCase := range testCases {
if got, want := ExpandStringListEmpty(testCase.configured), testCase.want; !cmp.Equal(got, want) {
t.Errorf("ExpandStringListEmpty(%v) = %v, want %v", testCase.configured, got, want)
}
}
}

func TestExpandStringTimeList(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 2dc1edb

Please sign in to comment.