Skip to content

Commit

Permalink
Add unit test for func WithoutEmpty in labels.go (prometheus#6848)
Browse files Browse the repository at this point in the history
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  • Loading branch information
Guangwen Feng authored Feb 19, 2020
1 parent c53bf31 commit 87971ff
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions pkg/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 87971ff

Please sign in to comment.