Skip to content

Commit

Permalink
add unit test for Contains
Browse files Browse the repository at this point in the history
Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
  • Loading branch information
Zhou Hao committed Dec 30, 2019
1 parent 0ea6d02 commit eff9402
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/pkg/slice/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
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",
srcs = ["slice.go"],
importpath = "k8s.io/kops/util/pkg/slice",
visibility = ["//visibility:public"],
)

go_test(
name = "go_default_test",
srcs = ["slice_test.go"],
embed = [":go_default_library"],
)
25 changes: 25 additions & 0 deletions util/pkg/slice/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit eff9402

Please sign in to comment.