Skip to content

Commit

Permalink
add missing tests for slice utils
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-the-programmer committed Mar 4, 2023
1 parent 69e4418 commit e9babcc
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions minikube/state_utils/slice_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package state_utils

import (
"reflect"
"testing"
)

func TestSliceOrNil(t *testing.T) {
type args struct {
slice []string
}
tests := []struct {
name string
args args
want []string
}{
{
name: "Should return non nil slice of type T",
args: args{
slice: []string{"abc"},
},
want: []string{"abc"},
},
{
name: "Should return nil",
args: args{
slice: []string{},
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := SliceOrNil(tt.args.slice); !reflect.DeepEqual(got, tt.want) {
t.Errorf("SliceOrNil() = %v, want %v", got, tt.want)
}
})
}
}

func TestReadSliceState(t *testing.T) {
type args struct {
slice interface{}
}
tests := []struct {
name string
args args
want []string
}{
{
name: "Should return string slice",
args: args{
slice: []string{"abc"},
},
want: []string{"abc"},
},
{
name: "Should construct string array",
args: args{
slice: []interface{}{"abc"},
},
want: []string{"abc"},
},
{
name: "Should return empty string array on unexpected type",
args: args{
slice: []int{},
},
want: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ReadSliceState(tt.args.slice); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReadSliceState() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit e9babcc

Please sign in to comment.