k3s/pkg/util/client_test.go
Derek Nola d5f560360e
Handle multiple arguments with StringSlice flags (#7380)
* Add helper function for multiple arguments in stringslice

Signed-off-by: Derek Nola <derek.nola@suse.com>

* Cleanup server setup with util function

Signed-off-by: Derek Nola <derek.nola@suse.com>
2023-05-02 09:55:48 -07:00

40 lines
821 B
Go

package util
import (
"reflect"
"testing"
"github.com/urfave/cli"
)
func Test_UnitSplitSliceString(t *testing.T) {
tests := []struct {
name string
arg cli.StringSlice
want []string
}{
{
name: "Single Argument",
arg: cli.StringSlice{"foo"},
want: []string{"foo"},
},
{
name: "Repeated Arguments",
arg: cli.StringSlice{"foo", "bar", "baz"},
want: []string{"foo", "bar", "baz"},
},
{
name: "Multiple Arguments and Repeated Arguments",
arg: cli.StringSlice{"foo,bar", "zoo,clar", "baz"},
want: []string{"foo", "bar", "zoo", "clar", "baz"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SplitStringSlice(tt.arg); !reflect.DeepEqual(got, tt.want) {
t.Errorf("SplitSliceString() = %+v\nWant = %+v", got, tt.want)
}
})
}
}