Add unit test

Signed-off-by: zouyu <zouy.fnst@cn.fujitsu.com>
pull/9533/head
zouyu 2020-10-23 10:10:01 +08:00
parent fa27e41087
commit 3130c9fce0
1 changed files with 33 additions and 0 deletions

View File

@ -43,3 +43,36 @@ func TestIsAddonValid(t *testing.T) {
})
}
}
func TestContains(t *testing.T) {
tests := []struct {
slice []string
str string
expected bool
}{
{
slice: []string{},
str: "test",
expected: false,
},
{
slice: []string{"test", "test1"},
str: "test1",
expected: true,
},
{
slice: []string{"test", "test1"},
str: "test2",
expected: false,
},
}
for _, test := range tests {
t.Run(test.str, func(t *testing.T) {
actual := contains(test.slice, test.str)
if test.expected != actual {
t.Fatalf("slice: %v\nstr: %v\nexpected: %v\nactual:%v\n", test.slice, test.str, test.expected, actual)
}
})
}
}