From b5ddc5d638787220976078127f824647c0019553 Mon Sep 17 00:00:00 2001 From: Koki Kato Date: Tue, 9 Feb 2021 23:01:21 +0900 Subject: [PATCH] Add test cases for silences with negative matchers Signed-off-by: Koki Kato --- api/v2/api_test.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/api/v2/api_test.go b/api/v2/api_test.go index e58ee020..7654687c 100644 --- a/api/v2/api_test.go +++ b/api/v2/api_test.go @@ -183,7 +183,36 @@ func TestCheckSilenceMatchesFilterLabels(t *testing.T) { []*labels.Matcher{createLabelMatcher("label", "value", labels.MatchEqual)}, false, }, - + { + []*silencepb.Matcher{createSilenceMatcher("label", "value", silencepb.Matcher_NOT_EQUAL)}, + []*labels.Matcher{createLabelMatcher("label", "value", labels.MatchNotEqual)}, + true, + }, + { + []*silencepb.Matcher{createSilenceMatcher("label", "value", silencepb.Matcher_NOT_REGEXP)}, + []*labels.Matcher{createLabelMatcher("label", "value", labels.MatchNotRegexp)}, + true, + }, + { + []*silencepb.Matcher{createSilenceMatcher("label", "value", silencepb.Matcher_EQUAL)}, + []*labels.Matcher{createLabelMatcher("label", "value", labels.MatchNotEqual)}, + false, + }, + { + []*silencepb.Matcher{createSilenceMatcher("label", "value", silencepb.Matcher_REGEXP)}, + []*labels.Matcher{createLabelMatcher("label", "value", labels.MatchNotRegexp)}, + false, + }, + { + []*silencepb.Matcher{createSilenceMatcher("label", "value", silencepb.Matcher_NOT_EQUAL)}, + []*labels.Matcher{createLabelMatcher("label", "value", labels.MatchNotRegexp)}, + false, + }, + { + []*silencepb.Matcher{createSilenceMatcher("label", "value", silencepb.Matcher_NOT_REGEXP)}, + []*labels.Matcher{createLabelMatcher("label", "value", labels.MatchNotEqual)}, + false, + }, { []*silencepb.Matcher{ createSilenceMatcher("label", "(foo|bar)", silencepb.Matcher_REGEXP),