Skip to content

Commit

Permalink
Support UTF-8 label matchers: Update compliance tests (#3569)
Browse files Browse the repository at this point in the history
* Update compliance tests

This commit updates compliance tests to include openmetrics
escape sequences that are not valid in the UTF-8 matchers parser.

Signed-off-by: George Robinson <[email protected]>

* Add tests for openmetrics escape sequences

Signed-off-by: George Robinson <[email protected]>

---------

Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana authored Oct 25, 2023
1 parent d250132 commit 8512285
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
64 changes: 62 additions & 2 deletions matchers/compliance/compliance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,74 @@ func TestCompliance(t *testing.T) {
skip: true,
},
{
input: "{foo=\\\"}",
input: `{foo=\n}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\n")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=bar\n}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\n")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=\t}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\\t")
return append(ms, m)
}(),
},
{
input: `{foo=bar\t}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\\t")
return append(ms, m)
}(),
},
{
input: `{foo=bar\}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\\")
return append(ms, m)
}(),
},
{
input: `{foo=bar\\}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\\")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=\"}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\"")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=bar\"}`,
want: func() labels.Matchers {
ms := labels.Matchers{}
m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\"")
return append(ms, m)
}(),
skip: true,
},
{
input: `{foo=bar}`,
want: func() labels.Matchers {
Expand Down Expand Up @@ -386,7 +446,7 @@ func TestCompliance(t *testing.T) {
t.Fatalf("expected error but got none: %v", tc.err)
}
if !reflect.DeepEqual(got, tc.want) {
t.Fatalf("labels not equal:\ngot %#v\nwant %#v", got, tc.want)
t.Fatalf("matchers not equal:\ngot %s\nwant %s", got, tc.want)
}
})
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/labels/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,30 @@ func TestMatchers(t *testing.T) {
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{}
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: `job=`,
want: func() []*Matcher {
Expand Down

0 comments on commit 8512285

Please sign in to comment.