From 002b391dfcdcd44092442f7cd93c6cab15a779a6 Mon Sep 17 00:00:00 2001 From: Hu Shuai Date: Thu, 9 Apr 2020 23:49:09 +0800 Subject: [PATCH] Add unit test for Has in pkg/labels/labels.go (#7039) This PR is about adding a unit test for Has in pkg/labels/labels.go. Signed-off-by: Hu Shuai --- pkg/labels/labels_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/labels/labels_test.go b/pkg/labels/labels_test.go index 44429ea03..cf82a8dde 100644 --- a/pkg/labels/labels_test.go +++ b/pkg/labels/labels_test.go @@ -453,3 +453,35 @@ func TestLabels_Compare(t *testing.T) { testutil.Equals(t, test.expected, got, "unexpected comparison result for test case %d", i) } } + +func TestLabels_Has(t *testing.T) { + tests := []struct { + input string + expected bool + }{ + { + input: "foo", + expected: false, + }, + { + input: "aaa", + expected: true, + }, + } + + labelsSet := Labels{ + { + Name: "aaa", + Value: "111", + }, + { + Name: "bbb", + Value: "222", + }, + } + + for i, test := range tests { + got := labelsSet.Has(test.input) + testutil.Equals(t, test.expected, got, "unexpected comparison result for test case %d", i) + } +}