Browse Source

Add unit tests in labels.go (#6921)

* Add unit test for func Equal in labels.go
* Add unit test for func Compare in labels.go

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
pull/6926/head
Guangwen Feng 5 years ago committed by GitHub
parent
commit
a128fc3534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 199
      pkg/labels/labels_test.go

199
pkg/labels/labels_test.go

@ -254,3 +254,202 @@ func TestLabels_WithoutEmpty(t *testing.T) {
testutil.Equals(t, test.expected, got, "unexpected labelset for test case %d", i)
}
}
func TestLabels_Equal(t *testing.T) {
labels := Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "222",
},
}
tests := []struct {
compared Labels
expected bool
}{
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "222",
},
{
Name: "ccc",
Value: "333",
},
},
expected: false,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bar",
Value: "222",
},
},
expected: false,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "233",
},
},
expected: false,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "222",
},
},
expected: true,
},
}
for i, test := range tests {
got := Equal(labels, test.compared)
testutil.Equals(t, test.expected, got, "unexpected comparison result for test case %d", i)
}
}
func TestLabels_Compare(t *testing.T) {
labels := Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "222",
},
}
tests := []struct {
compared Labels
expected int
}{
{
compared: Labels{
{
Name: "aaa",
Value: "110",
},
{
Name: "bbb",
Value: "222",
},
},
expected: 1,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "233",
},
},
expected: -1,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bar",
Value: "222",
},
},
expected: 1,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbc",
Value: "222",
},
},
expected: -1,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
},
expected: 1,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "222",
},
{
Name: "ccc",
Value: "333",
},
{
Name: "ddd",
Value: "444",
},
},
expected: -2,
},
{
compared: Labels{
{
Name: "aaa",
Value: "111",
},
{
Name: "bbb",
Value: "222",
},
},
expected: 0,
},
}
for i, test := range tests {
got := Compare(labels, test.compared)
testutil.Equals(t, test.expected, got, "unexpected comparison result for test case %d", i)
}
}

Loading…
Cancel
Save