From eff94028ddf6da11a07df72d8da918ade85785ef Mon Sep 17 00:00:00 2001 From: Zhou Hao Date: Sun, 29 Dec 2019 15:35:06 +0800 Subject: [PATCH] add unit test for Contains Signed-off-by: Zhou Hao --- util/pkg/slice/BUILD.bazel | 8 +++++++- util/pkg/slice/slice_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/util/pkg/slice/BUILD.bazel b/util/pkg/slice/BUILD.bazel index 35134bf3a1..59321d1125 100644 --- a/util/pkg/slice/BUILD.bazel +++ b/util/pkg/slice/BUILD.bazel @@ -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"], +) diff --git a/util/pkg/slice/slice_test.go b/util/pkg/slice/slice_test.go index 31e6dbe6f5..58e1175cf8 100644 --- a/util/pkg/slice/slice_test.go +++ b/util/pkg/slice/slice_test.go @@ -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) + } + } +}