Skip to content

Commit 0e3f5c6

Browse files
committed
prometheus/testutil/testutil_test.go: compare complete error
Before we would only compare the error prefix in `TestScrapeAndCompare`. Signed-off-by: leonnicolas <[email protected]>
1 parent 9490310 commit 0e3f5c6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

prometheus/testutil/testutil_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ func TestScrapeAndCompare(t *testing.T) {
331331
scenarios := map[string]struct {
332332
want string
333333
metricNames []string
334-
// expectedErrPrefix if empty, means no fail is expected for the comparison.
335-
expectedErrPrefix string
334+
// expectedErr if empty, means no fail is expected for the comparison.
335+
expectedErr string
336336
}{
337337
"empty metric Names": {
338338
want: `
@@ -378,8 +378,8 @@ func TestScrapeAndCompare(t *testing.T) {
378378
379379
some_total2{ label2 = "value2" } 1
380380
`,
381-
metricNames: []string{"some_total3"},
382-
expectedErrPrefix: "expected metric name(s) not found",
381+
metricNames: []string{"some_total3"},
382+
expectedErr: "expected metric name(s) not found: [some_total3]",
383383
},
384384
"one of multiple expected metric names is not scraped": {
385385
want: `
@@ -393,8 +393,8 @@ func TestScrapeAndCompare(t *testing.T) {
393393
394394
some_total2{ label2 = "value2" } 1
395395
`,
396-
metricNames: []string{"some_total1", "some_total3"},
397-
expectedErrPrefix: "expected metric name(s) not found",
396+
metricNames: []string{"some_total1", "some_total3"},
397+
expectedErr: "expected metric name(s) not found: [some_total1 some_total3]",
398398
},
399399
}
400400
for name, scenario := range scenarios {
@@ -406,10 +406,10 @@ func TestScrapeAndCompare(t *testing.T) {
406406
}))
407407
defer ts.Close()
408408
if err := ScrapeAndCompare(ts.URL, expectedReader, scenario.metricNames...); err != nil {
409-
if scenario.expectedErrPrefix == "" || !strings.HasPrefix(err.Error(), scenario.expectedErrPrefix) {
409+
if scenario.expectedErr == "" || err.Error() != scenario.expectedErr {
410410
t.Errorf("unexpected error happened: %s", err)
411411
}
412-
} else if scenario.expectedErrPrefix != "" {
412+
} else if scenario.expectedErr != "" {
413413
t.Errorf("expected an error but got nil")
414414
}
415415
})

0 commit comments

Comments
 (0)