@@ -335,8 +335,8 @@ func TestScrapeAndCompare(t *testing.T) {
335
335
scenarios := map [string ]struct {
336
336
want string
337
337
metricNames []string
338
- errPrefix string
339
- fail bool
338
+ // expectedErrPrefix if empty, means no fail is expected for the comparison.
339
+ expectedErrPrefix string
340
340
}{
341
341
"empty metric Names" : {
342
342
want : `
@@ -382,9 +382,8 @@ func TestScrapeAndCompare(t *testing.T) {
382
382
383
383
some_total2{ label2 = "value2" } 1
384
384
` ,
385
- metricNames : []string {"some_total3" },
386
- errPrefix : "expected metric name(s) not found" ,
387
- fail : true ,
385
+ metricNames : []string {"some_total3" },
386
+ expectedErrPrefix : "expected metric name(s) not found" ,
388
387
},
389
388
"one of multiple expected metric names is not scraped" : {
390
389
want : `
@@ -398,9 +397,8 @@ func TestScrapeAndCompare(t *testing.T) {
398
397
399
398
some_total2{ label2 = "value2" } 1
400
399
` ,
401
- metricNames : []string {"some_total1" , "some_total3" },
402
- errPrefix : "expected metric name(s) not found" ,
403
- fail : true ,
400
+ metricNames : []string {"some_total1" , "some_total3" },
401
+ expectedErrPrefix : "expected metric name(s) not found" ,
404
402
},
405
403
}
406
404
for name , scenario := range scenarios {
@@ -412,10 +410,10 @@ func TestScrapeAndCompare(t *testing.T) {
412
410
}))
413
411
defer ts .Close ()
414
412
if err := ScrapeAndCompare (ts .URL , expectedReader , scenario .metricNames ... ); err != nil {
415
- if ! scenario .fail || ! strings .HasPrefix (err .Error (), scenario .errPrefix ) {
413
+ if scenario .expectedErrPrefix == "" || ! strings .HasPrefix (err .Error (), scenario .expectedErrPrefix ) {
416
414
t .Errorf ("unexpected error happened: %s" , err )
417
415
}
418
- } else if scenario .fail {
416
+ } else if scenario .expectedErrPrefix != "" {
419
417
t .Errorf ("expected an error but got nil" )
420
418
}
421
419
})
0 commit comments