diff --git a/pkg/labels/parse_test.go b/pkg/labels/parse_test.go index e1203f4a..e30d13c4 100644 --- a/pkg/labels/parse_test.go +++ b/pkg/labels/parse_test.go @@ -24,6 +24,42 @@ func TestMatchers(t *testing.T) { want []*Matcher err string }{ + { + input: `{}`, + want: make([]*Matcher, 0), + }, + { + input: `{foo='}`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "'") + return append(ms, m) + }(), + }, + { + input: "{foo=`}", + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "`") + return append(ms, m) + }(), + }, + { + input: "{foo=\\\"}", + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "\"") + return append(ms, m) + }(), + }, + { + input: `{foo=bar}`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "bar") + return append(ms, m) + }(), + }, { input: `{foo="bar"}`, want: func() []*Matcher { @@ -32,6 +68,14 @@ func TestMatchers(t *testing.T) { return append(ms, m) }(), }, + { + input: `{foo=~bar.*}`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchRegexp, "foo", "bar.*") + return append(ms, m) + }(), + }, { input: `{foo=~"bar.*"}`, want: func() []*Matcher { @@ -40,6 +84,14 @@ func TestMatchers(t *testing.T) { return append(ms, m) }(), }, + { + input: `{foo!=bar}`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchNotEqual, "foo", "bar") + return append(ms, m) + }(), + }, { input: `{foo!="bar"}`, want: func() []*Matcher { @@ -48,6 +100,14 @@ func TestMatchers(t *testing.T) { return append(ms, m) }(), }, + { + input: `{foo!~bar.*}`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchNotRegexp, "foo", "bar.*") + return append(ms, m) + }(), + }, { input: `{foo!~"bar.*"}`, want: func() []*Matcher { @@ -189,6 +249,31 @@ func TestMatchers(t *testing.T) { return append(ms, m, m2) }(), }, + { + input: `{foo=bar}}`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "bar}") + return append(ms, m) + }(), + }, + { + input: `{foo=bar}},}`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "bar}}") + return append(ms, m) + }(), + }, + { + input: `{foo=,bar=}}`, + want: func() []*Matcher { + ms := []*Matcher{} + m1, _ := NewMatcher(MatchEqual, "foo", "") + m2, _ := NewMatcher(MatchEqual, "bar", "}") + return append(ms, m1, m2) + }(), + }, { input: `job=`, want: func() []*Matcher { @@ -245,6 +330,26 @@ func TestMatchers(t *testing.T) { input: `"foo="bar""`, err: `bad matcher format: "foo="bar""`, }, + { + input: `{{foo=`, + err: `bad matcher format: {foo=`, + }, + { + input: `{foo=`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "") + return append(ms, m) + }(), + }, + { + input: `{foo=}b`, + want: func() []*Matcher { + ms := []*Matcher{} + m, _ := NewMatcher(MatchEqual, "foo", "}b") + return append(ms, m) + }(), + }, } { t.Run(tc.input, func(t *testing.T) { got, err := ParseMatchers(tc.input)