From 87971fff907386ff2ab9f3c92411b7190e5d809c Mon Sep 17 00:00:00 2001 From: Guangwen Feng Date: Wed, 19 Feb 2020 19:56:12 +0800 Subject: [PATCH] Add unit test for func WithoutEmpty in labels.go (#6848) Signed-off-by: Guangwen Feng --- pkg/labels/labels_test.go | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/pkg/labels/labels_test.go b/pkg/labels/labels_test.go index a8d319c52..1375eadd3 100644 --- a/pkg/labels/labels_test.go +++ b/pkg/labels/labels_test.go @@ -175,3 +175,82 @@ func TestLabels_HasDuplicateLabelNames(t *testing.T) { testutil.Equals(t, c.LabelName, l, "test %d: incorrect label name", i) } } + +func TestLabels_WithoutEmpty(t *testing.T) { + tests := []struct { + input Labels + expected Labels + }{ + { + input: Labels{ + { + Name: "__name__", + Value: "test", + }, + { + Name: "foo", + }, + { + Name: "hostname", + Value: "localhost", + }, + { + Name: "bar", + }, + { + Name: "job", + Value: "check", + }, + }, + expected: Labels{ + { + Name: "__name__", + Value: "test", + }, + { + Name: "hostname", + Value: "localhost", + }, + { + Name: "job", + Value: "check", + }, + }, + }, + { + input: Labels{ + { + Name: "__name__", + Value: "test", + }, + { + Name: "hostname", + Value: "localhost", + }, + { + Name: "job", + Value: "check", + }, + }, + expected: Labels{ + { + Name: "__name__", + Value: "test", + }, + { + Name: "hostname", + Value: "localhost", + }, + { + Name: "job", + Value: "check", + }, + }, + }, + } + + for i, test := range tests { + got := test.input.WithoutEmpty() + testutil.Equals(t, test.expected, got, "unexpected labelset for test case %d", i) + } +}