From e5ffa8c9a08a5ee4185271c8c26051ddc1388b7a Mon Sep 17 00:00:00 2001 From: Hu Shuai Date: Mon, 8 Jun 2020 15:46:21 +0800 Subject: [PATCH] Add some unit tests for pkg/labels/labels.go (#7358) This PR is about adding some unit tests for pkg/labels/labels.go. Signed-off-by: Hu Shuai --- pkg/labels/labels_test.go | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/pkg/labels/labels_test.go b/pkg/labels/labels_test.go index 51faea985..00d3f6a0a 100644 --- a/pkg/labels/labels_test.go +++ b/pkg/labels/labels_test.go @@ -544,3 +544,71 @@ func TestLabels_WithoutLabels(t *testing.T) { func TestLabels_FromStrings(t *testing.T) { testutil.Equals(t, Labels{{"aaa", "111"}, {"bbb", "222"}}, FromStrings("aaa", "111", "bbb", "222")) } + +func TestBulider_NewBulider(t *testing.T) { + testutil.Equals( + t, + &Builder{ + base: Labels{{"aaa", "111"}}, + del: []string{}, + add: []Label{}, + }, + NewBuilder(Labels{{"aaa", "111"}}), + ) +} + +func TestBuilder_Del(t *testing.T) { + testutil.Equals( + t, + &Builder{ + del: []string{"bbb"}, + add: []Label{{"aaa", "111"}, {"ccc", "333"}}, + }, + (&Builder{ + del: []string{}, + add: []Label{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}}, + }).Del("bbb"), + ) +} + +func TestBuilder_Set(t *testing.T) { + testutil.Equals( + t, + &Builder{ + base: Labels{{"aaa", "111"}}, + del: []string{}, + add: []Label{{"bbb", "222"}}, + }, + (&Builder{ + base: Labels{{"aaa", "111"}}, + del: []string{}, + add: []Label{}, + }).Set("bbb", "222"), + ) + + testutil.Equals( + t, + &Builder{ + base: Labels{{"aaa", "111"}}, + del: []string{}, + add: []Label{{"bbb", "333"}}, + }, + (&Builder{ + base: Labels{{"aaa", "111"}}, + del: []string{}, + add: []Label{{"bbb", "222"}}, + }).Set("bbb", "333"), + ) +} + +func TestBuilder_Labels(t *testing.T) { + testutil.Equals( + t, + Labels{{"aaa", "111"}, {"ccc", "333"}, {"ddd", "444"}}, + (&Builder{ + base: Labels{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}}, + del: []string{"bbb"}, + add: []Label{{"ddd", "444"}}, + }).Labels(), + ) +}