@@ -331,8 +331,8 @@ func TestScrapeAndCompare(t *testing.T) {
331
331
scenarios := map [string ]struct {
332
332
want string
333
333
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
336
336
}{
337
337
"empty metric Names" : {
338
338
want : `
@@ -378,8 +378,8 @@ func TestScrapeAndCompare(t *testing.T) {
378
378
379
379
some_total2{ label2 = "value2" } 1
380
380
` ,
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] " ,
383
383
},
384
384
"one of multiple expected metric names is not scraped" : {
385
385
want : `
@@ -393,8 +393,8 @@ func TestScrapeAndCompare(t *testing.T) {
393
393
394
394
some_total2{ label2 = "value2" } 1
395
395
` ,
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] " ,
398
398
},
399
399
}
400
400
for name , scenario := range scenarios {
@@ -406,10 +406,10 @@ func TestScrapeAndCompare(t *testing.T) {
406
406
}))
407
407
defer ts .Close ()
408
408
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 {
410
410
t .Errorf ("unexpected error happened: %s" , err )
411
411
}
412
- } else if scenario .expectedErrPrefix != "" {
412
+ } else if scenario .expectedErr != "" {
413
413
t .Errorf ("expected an error but got nil" )
414
414
}
415
415
})
0 commit comments