mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-14 09:34:05 -08:00
Reintroduce tests.
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This commit is contained in:
parent
7dab60e56d
commit
715274ec9d
|
@ -205,49 +205,49 @@ func Test_OptimizeRegex(t *testing.T) {
|
||||||
pattern string
|
pattern string
|
||||||
exp StringMatcher
|
exp StringMatcher
|
||||||
}{
|
}{
|
||||||
// {".*", anyStringMatcher{allowEmpty: true, matchNL: false}},
|
{".*", &anyStringMatcher{allowEmpty: true, matchNL: false}},
|
||||||
// {".*?", anyStringMatcher{allowEmpty: true, matchNL: false}},
|
{".*?", &anyStringMatcher{allowEmpty: true, matchNL: false}},
|
||||||
// {"(?s:.*)", anyStringMatcher{allowEmpty: true, matchNL: true}},
|
{"(?s:.*)", &anyStringMatcher{allowEmpty: true, matchNL: true}},
|
||||||
// {"(.*)", anyStringMatcher{allowEmpty: true, matchNL: false}},
|
{"(.*)", &anyStringMatcher{allowEmpty: true, matchNL: false}},
|
||||||
// {"^.*$", anyStringMatcher{allowEmpty: true, matchNL: false}},
|
{"^.*$", &anyStringMatcher{allowEmpty: true, matchNL: false}},
|
||||||
// {".+", anyStringMatcher{allowEmpty: false, matchNL: false}},
|
{".+", &anyStringMatcher{allowEmpty: false, matchNL: false}},
|
||||||
// {"(?s:.+)", anyStringMatcher{allowEmpty: false, matchNL: true}},
|
{"(?s:.+)", &anyStringMatcher{allowEmpty: false, matchNL: true}},
|
||||||
// {"^.+$", anyStringMatcher{allowEmpty: false, matchNL: false}},
|
{"^.+$", &anyStringMatcher{allowEmpty: false, matchNL: false}},
|
||||||
// {"(.+)", anyStringMatcher{allowEmpty: false, matchNL: false}},
|
{"(.+)", &anyStringMatcher{allowEmpty: false, matchNL: false}},
|
||||||
// {"", emptyStringMatcher{}},
|
{"", emptyStringMatcher{}},
|
||||||
// {"^$", emptyStringMatcher{}},
|
{"^$", emptyStringMatcher{}},
|
||||||
// {"^foo$", equalStringMatcher{s: "foo", caseSensitive: true}},
|
{"^foo$", &equalStringMatcher{s: "foo", caseSensitive: true}},
|
||||||
// {"^(?i:foo)$", equalStringMatcher{s: "FOO", caseSensitive: false}},
|
{"^(?i:foo)$", &equalStringMatcher{s: "FOO", caseSensitive: false}},
|
||||||
// {"^(?i:foo)|(bar)$", orStringMatcher([]StringMatcher{equalStringMatcher{s: "FOO", caseSensitive: false}, equalStringMatcher{s: "bar", caseSensitive: true}})},
|
{"^(?i:foo)|(bar)$", orStringMatcher([]StringMatcher{&equalStringMatcher{s: "FOO", caseSensitive: false}, &equalStringMatcher{s: "bar", caseSensitive: true}})},
|
||||||
// {"^(?i:foo|oo)|(bar)$", orStringMatcher([]StringMatcher{orStringMatcher([]StringMatcher{equalStringMatcher{s: "FOO", caseSensitive: false}, equalStringMatcher{s: "OO", caseSensitive: false}}), equalStringMatcher{s: "bar", caseSensitive: true}})},
|
{"^(?i:foo|oo)|(bar)$", orStringMatcher([]StringMatcher{orStringMatcher([]StringMatcher{&equalStringMatcher{s: "FOO", caseSensitive: false}, &equalStringMatcher{s: "OO", caseSensitive: false}}), &equalStringMatcher{s: "bar", caseSensitive: true}})},
|
||||||
// {".*foo.*", containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
{".*foo.*", &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
||||||
// {"(.*)foo.*", containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
{"(.*)foo.*", &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
||||||
// {"(.*)foo(.*)", containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
{"(.*)foo(.*)", &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
||||||
// {"(.+)foo(.*)", containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: false, matchNL: false}, right: anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
{"(.+)foo(.*)", &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: false, matchNL: false}, right: &anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
||||||
// {"^.+foo.+", containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: false, matchNL: false}, right: anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
{"^.+foo.+", &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: false, matchNL: false}, right: &anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
||||||
// {"^(.*)(foo)(.*)$", containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
{"^(.*)(foo)(.*)$", &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
||||||
// {"^(.*)(foo|foobar)(.*)$", containsStringMatcher{substrings: []string{"foo", "foobar"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
{"^(.*)(foo|foobar)(.*)$", &containsStringMatcher{substrings: []string{"foo", "foobar"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
||||||
// {"^(.*)(foo|foobar)(.+)$", containsStringMatcher{substrings: []string{"foo", "foobar"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
{"^(.*)(foo|foobar)(.+)$", &containsStringMatcher{substrings: []string{"foo", "foobar"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
||||||
// {"^(.*)(bar|b|buzz)(.+)$", containsStringMatcher{substrings: []string{"bar", "b", "buzz"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
{"^(.*)(bar|b|buzz)(.+)$", &containsStringMatcher{substrings: []string{"bar", "b", "buzz"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
||||||
// {"10\\.0\\.(1|2)\\.+", nil},
|
{"10\\.0\\.(1|2)\\.+", nil},
|
||||||
// {"10\\.0\\.(1|2).+", containsStringMatcher{substrings: []string{"10.0.1", "10.0.2"}, left: nil, right: anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
{"10\\.0\\.(1|2).+", &containsStringMatcher{substrings: []string{"10.0.1", "10.0.2"}, left: nil, right: &anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
||||||
// {"^.+foo", containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: false, matchNL: false}, right: nil}},
|
{"^.+foo", &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: false, matchNL: false}, right: nil}},
|
||||||
// {"foo-.*$", containsStringMatcher{substrings: []string{"foo-"}, left: nil, right: anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
{"foo-.*$", &containsStringMatcher{substrings: []string{"foo-"}, left: nil, right: &anyStringMatcher{allowEmpty: true, matchNL: false}}},
|
||||||
// {"(prometheus|api_prom)_api_v1_.+", containsStringMatcher{substrings: []string{"prometheus_api_v1_", "api_prom_api_v1_"}, left: nil, right: anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
{"(prometheus|api_prom)_api_v1_.+", &containsStringMatcher{substrings: []string{"prometheus_api_v1_", "api_prom_api_v1_"}, left: nil, right: &anyStringMatcher{allowEmpty: false, matchNL: false}}},
|
||||||
// {"^((.*)(bar|b|buzz)(.+)|foo)$", orStringMatcher([]StringMatcher{containsStringMatcher{substrings: []string{"bar", "b", "buzz"}, left: anyStringMatcher{allowEmpty: true, matchNL: false}, right: anyStringMatcher{allowEmpty: false, matchNL: false}}, equalStringMatcher{s: "foo", caseSensitive: true}})},
|
{"^((.*)(bar|b|buzz)(.+)|foo)$", orStringMatcher([]StringMatcher{&containsStringMatcher{substrings: []string{"bar", "b", "buzz"}, left: &anyStringMatcher{allowEmpty: true, matchNL: false}, right: &anyStringMatcher{allowEmpty: false, matchNL: false}}, &equalStringMatcher{s: "foo", caseSensitive: true}})},
|
||||||
// {"((fo(bar))|.+foo)", orStringMatcher([]StringMatcher{orStringMatcher([]StringMatcher{equalStringMatcher{s: "fobar", caseSensitive: true}}), containsStringMatcher{substrings: []string{"foo"}, left: anyStringMatcher{allowEmpty: false, matchNL: false}, right: nil}})},
|
{"((fo(bar))|.+foo)", orStringMatcher([]StringMatcher{orStringMatcher([]StringMatcher{&equalStringMatcher{s: "fobar", caseSensitive: true}}), &containsStringMatcher{substrings: []string{"foo"}, left: &anyStringMatcher{allowEmpty: false, matchNL: false}, right: nil}})},
|
||||||
// {"(.+)/(gateway|cortex-gw|cortex-gw-internal)", containsStringMatcher{substrings: []string{"/gateway", "/cortex-gw", "/cortex-gw-internal"}, left: anyStringMatcher{allowEmpty: false, matchNL: false}, right: nil}},
|
{"(.+)/(gateway|cortex-gw|cortex-gw-internal)", &containsStringMatcher{substrings: []string{"/gateway", "/cortex-gw", "/cortex-gw-internal"}, left: &anyStringMatcher{allowEmpty: false, matchNL: false}, right: nil}},
|
||||||
// // we don't support case insensitive matching for contains.
|
// we don't support case insensitive matching for contains.
|
||||||
// // This is because there's no strings.IndexOfFold function.
|
// This is because there's no strings.IndexOfFold function.
|
||||||
// // We can revisit later if this is really popular by using strings.ToUpper.
|
// We can revisit later if this is really popular by using strings.ToUpper.
|
||||||
// {"^(.*)((?i)foo|foobar)(.*)$", nil},
|
{"^(.*)((?i)foo|foobar)(.*)$", nil},
|
||||||
// {"(api|rpc)_(v1|prom)_((?i)push|query)", nil},
|
{"(api|rpc)_(v1|prom)_((?i)push|query)", nil},
|
||||||
// {"[a-z][a-z]", nil},
|
{"[a-z][a-z]", nil},
|
||||||
// {"[1^3]", nil},
|
{"[1^3]", nil},
|
||||||
// // This one is not supported because `stringMatcherFromRegexp` is not reentrant for syntax.OpConcat.
|
// This one is not supported because `stringMatcherFromRegexp` is not reentrant for syntax.OpConcat.
|
||||||
// // It would make the code too complex to handle it.
|
// It would make the code too complex to handle it.
|
||||||
// {"/|/bar.*", nil},
|
{"/|/bar.*", nil},
|
||||||
// {"(.+)/(foo.*|bar$)", nil},
|
{"(.+)/(foo.*|bar$)", nil},
|
||||||
} {
|
} {
|
||||||
c := c
|
c := c
|
||||||
t.Run(c.pattern, func(t *testing.T) {
|
t.Run(c.pattern, func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue