add unit test for Contains

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
This commit is contained in:
Zhou Hao 2019-12-29 15:35:06 +08:00
parent 0ea6d02c54
commit eff94028dd
2 changed files with 32 additions and 1 deletions

View File

@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
@ -6,3 +6,9 @@ go_library(
importpath = "k8s.io/kops/util/pkg/slice",
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["slice_test.go"],
embed = [":go_default_library"],
)

View File

@ -45,3 +45,28 @@ func TestGetUniqueStrings(t *testing.T) {
}
}
}
func TestContains(t *testing.T) {
tests := []struct {
listStr []string
e string
contains bool
}{
{
listStr: []string{"a", "b"},
e: "a",
contains: true,
},
{
listStr: []string{"a", "b"},
e: "c",
contains: false,
},
}
for _, test := range tests {
contains := Contains(test.listStr, test.e)
if test.contains != contains {
t.Errorf("Expected %v, got %v", test.contains, contains)
}
}
}