Skip to content

Commit

Permalink
prometheus/testutil/testutil_test.go: compare complete error
Browse files Browse the repository at this point in the history
Before we would only compare the error prefix in `TestScrapeAndCompare`.

Signed-off-by: leonnicolas <leonloechner@gmx.de>
  • Loading branch information
leonnicolas committed May 15, 2024
1 parent 9490310 commit 0e3f5c6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions prometheus/testutil/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ func TestScrapeAndCompare(t *testing.T) {
scenarios := map[string]struct {
want string
metricNames []string
// expectedErrPrefix if empty, means no fail is expected for the comparison.
expectedErrPrefix string
// expectedErr if empty, means no fail is expected for the comparison.
expectedErr string
}{
"empty metric Names": {
want: `
Expand Down Expand Up @@ -378,8 +378,8 @@ func TestScrapeAndCompare(t *testing.T) {
some_total2{ label2 = "value2" } 1
`,
metricNames: []string{"some_total3"},
expectedErrPrefix: "expected metric name(s) not found",
metricNames: []string{"some_total3"},
expectedErr: "expected metric name(s) not found: [some_total3]",
},
"one of multiple expected metric names is not scraped": {
want: `
Expand All @@ -393,8 +393,8 @@ func TestScrapeAndCompare(t *testing.T) {
some_total2{ label2 = "value2" } 1
`,
metricNames: []string{"some_total1", "some_total3"},
expectedErrPrefix: "expected metric name(s) not found",
metricNames: []string{"some_total1", "some_total3"},
expectedErr: "expected metric name(s) not found: [some_total1 some_total3]",
},
}
for name, scenario := range scenarios {
Expand All @@ -406,10 +406,10 @@ func TestScrapeAndCompare(t *testing.T) {
}))
defer ts.Close()
if err := ScrapeAndCompare(ts.URL, expectedReader, scenario.metricNames...); err != nil {
if scenario.expectedErrPrefix == "" || !strings.HasPrefix(err.Error(), scenario.expectedErrPrefix) {
if scenario.expectedErr == "" || err.Error() != scenario.expectedErr {
t.Errorf("unexpected error happened: %s", err)
}
} else if scenario.expectedErrPrefix != "" {
} else if scenario.expectedErr != "" {
t.Errorf("expected an error but got nil")
}
})
Expand Down

0 comments on commit 0e3f5c6

Please sign in to comment.