mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
Add unit test for Inverse in pkg/labels/matcher.go (#6586)
This PR is about adding a unit test for Inverse and updating the other test in pkg/labels/matcher.go. Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
This commit is contained in:
parent
e3239c1093
commit
a7f16749b7
|
@ -13,13 +13,15 @@
|
||||||
|
|
||||||
package labels
|
package labels
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
|
)
|
||||||
|
|
||||||
func mustNewMatcher(t *testing.T, mType MatchType, value string) *Matcher {
|
func mustNewMatcher(t *testing.T, mType MatchType, value string) *Matcher {
|
||||||
m, err := NewMatcher(mType, "", value)
|
m, err := NewMatcher(mType, "", value)
|
||||||
if err != nil {
|
testutil.Ok(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +84,36 @@ func TestMatcher(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if test.matcher.Matches(test.value) != test.match {
|
testutil.Equals(t, test.matcher.Matches(test.value), test.match)
|
||||||
t.Fatalf("Unexpected match result for matcher %v and value %q; want %v, got %v", test.matcher, test.value, test.match, !test.match)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInverse(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
matcher *Matcher
|
||||||
|
expected *Matcher
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
matcher: &Matcher{Type: MatchEqual, Name: "name1", Value: "value1"},
|
||||||
|
expected: &Matcher{Type: MatchNotEqual, Name: "name1", Value: "value1"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matcher: &Matcher{Type: MatchNotEqual, Name: "name2", Value: "value2"},
|
||||||
|
expected: &Matcher{Type: MatchEqual, Name: "name2", Value: "value2"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matcher: &Matcher{Type: MatchRegexp, Name: "name3", Value: "value3"},
|
||||||
|
expected: &Matcher{Type: MatchNotRegexp, Name: "name3", Value: "value3"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
matcher: &Matcher{Type: MatchNotRegexp, Name: "name4", Value: "value4"},
|
||||||
|
expected: &Matcher{Type: MatchRegexp, Name: "name4", Value: "value4"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
result, err := test.matcher.Inverse()
|
||||||
|
testutil.Ok(t, err)
|
||||||
|
testutil.Equals(t, test.expected.Type, result.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue