-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
50 lines (45 loc) · 1.5 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"testing"
"github.com/prometheus/prometheus/model/labels"
)
func TestLabelsEqual(t *testing.T) {
t.Run("equal labels", func(t *testing.T) {
l1 := []*labels.Matcher{
{Name: "job", Type: labels.MatchEqual, Value: "node_exporter"},
{Name: "instance", Type: labels.MatchEqual, Value: "localhost:9100"},
}
l2 := []*labels.Matcher{
{Name: "job", Type: labels.MatchEqual, Value: "node_exporter"},
{Name: "instance", Type: labels.MatchEqual, Value: "localhost:9100"},
}
if !labelsEqual(l1, l2) {
t.Errorf("expected labelsEqual to return true, but got false")
}
})
t.Run("unequal labels", func(t *testing.T) {
l1 := []*labels.Matcher{
{Name: "job", Type: labels.MatchEqual, Value: "node_exporter"},
{Name: "instance", Type: labels.MatchEqual, Value: "localhost:9100"},
}
l2 := []*labels.Matcher{
{Name: "job", Type: labels.MatchEqual, Value: "node_exporter"},
{Name: "instance", Type: labels.MatchEqual, Value: "localhost:9090"},
}
if labelsEqual(l1, l2) {
t.Errorf("expected labelsEqual to return false, but got true")
}
})
t.Run("unequal number of labels", func(t *testing.T) {
l1 := []*labels.Matcher{
{Name: "job", Type: labels.MatchEqual, Value: "node_exporter"},
{Name: "instance", Type: labels.MatchEqual, Value: "localhost:9100"},
}
l2 := []*labels.Matcher{
{Name: "job", Type: labels.MatchEqual, Value: "node_exporter"},
}
if labelsEqual(l1, l2) {
t.Errorf("expected labelsEqual to return false, but got true")
}
})
}