Support UTF-8 label matchers: Update compliance tests (#3569)

* 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 <george.robinson@grafana.com>

* Add tests for openmetrics escape sequences

Signed-off-by: George Robinson <george.robinson@grafana.com>

---------

Signed-off-by: George Robinson <george.robinson@grafana.com>
This commit is contained in:
George Robinson 2023-10-25 09:52:17 +01:00 committed by GitHub
parent d2501323d2
commit 8512285e54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 2 deletions

View File

@ -52,7 +52,58 @@ 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", "\"")
@ -60,6 +111,15 @@ func TestCompliance(t *testing.T) {
}(),
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 {
@ -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)
}
})
}

View File

@ -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 {