From 2d9480862dfdce67740694d87c37f4d7d768a6b5 Mon Sep 17 00:00:00 2001 From: George Robinson Date: Tue, 24 Oct 2023 22:25:55 +0100 Subject: [PATCH 1/2] 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 --- matchers/compliance/compliance_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/matchers/compliance/compliance_test.go b/matchers/compliance/compliance_test.go index 9178e058b2..7d97dca16e 100644 --- a/matchers/compliance/compliance_test.go +++ b/matchers/compliance/compliance_test.go @@ -60,6 +60,24 @@ func TestCompliance(t *testing.T) { }(), skip: true, }, + { + 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=\\t}", + want: func() labels.Matchers { + ms := labels.Matchers{} + m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\t") + return append(ms, m) + }(), + skip: true, + }, { input: `{foo=bar}`, want: func() labels.Matchers { @@ -386,7 +404,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) } }) } From cfd0e859e763e9dc2b1704a00daec539574c79f2 Mon Sep 17 00:00:00 2001 From: George Robinson Date: Tue, 24 Oct 2023 23:03:30 +0100 Subject: [PATCH 2/2] Add tests for openmetrics escape sequences Signed-off-by: George Robinson --- matchers/compliance/compliance_test.go | 54 +++++++++++++++++++++++--- pkg/labels/parse_test.go | 24 ++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) diff --git a/matchers/compliance/compliance_test.go b/matchers/compliance/compliance_test.go index 7d97dca16e..705c4c4315 100644 --- a/matchers/compliance/compliance_test.go +++ b/matchers/compliance/compliance_test.go @@ -52,28 +52,70 @@ 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", "\"") + m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\n") return append(ms, m) }(), skip: true, }, { - input: "{foo=\\n}", + input: `{foo=bar\n}`, want: func() labels.Matchers { ms := labels.Matchers{} - m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\n") + 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=\\t}", + input: `{foo=bar\"}`, want: func() labels.Matchers { ms := labels.Matchers{} - m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "\t") + m, _ := labels.NewMatcher(labels.MatchEqual, "foo", "bar\"") return append(ms, m) }(), skip: true, diff --git a/pkg/labels/parse_test.go b/pkg/labels/parse_test.go index b4b1d631d4..dd1731c9b7 100644 --- a/pkg/labels/parse_test.go +++ b/pkg/labels/parse_test.go @@ -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 {