From 6ff4814a492ae6f9e3f5cf7b022a823b631b7a95 Mon Sep 17 00:00:00 2001 From: Hu Shuai Date: Fri, 5 Jun 2020 16:48:33 +0800 Subject: [PATCH] Add some unit tests for pkg/labels/labels.go (#7347) This PR is about adding some unit tests for pkg/labels/labels.go. Signed-off-by: Hu Shuai --- pkg/labels/labels_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/labels/labels_test.go b/pkg/labels/labels_test.go index 7bffff8af..51faea985 100644 --- a/pkg/labels/labels_test.go +++ b/pkg/labels/labels_test.go @@ -531,3 +531,16 @@ func TestLabels_Copy(t *testing.T) { func TestLabels_Map(t *testing.T) { testutil.Equals(t, map[string]string{"aaa": "111", "bbb": "222"}, Labels{{"aaa", "111"}, {"bbb", "222"}}.Map()) } + +func TestLabels_WithLabels(t *testing.T) { + testutil.Equals(t, Labels{{"aaa", "111"}, {"bbb", "222"}}, Labels{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}}.WithLabels("aaa", "bbb")) +} + +func TestLabels_WithoutLabels(t *testing.T) { + testutil.Equals(t, Labels{{"aaa", "111"}}, Labels{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}}.WithoutLabels("bbb", "ccc")) + testutil.Equals(t, Labels{{"aaa", "111"}}, Labels{{"aaa", "111"}, {"bbb", "222"}, {MetricName, "333"}}.WithoutLabels("bbb")) +} + +func TestLabels_FromStrings(t *testing.T) { + testutil.Equals(t, Labels{{"aaa", "111"}, {"bbb", "222"}}, FromStrings("aaa", "111", "bbb", "222")) +}