@@ -335,8 +335,8 @@ func TestScrapeAndCompare(t *testing.T) {
335335 scenarios := map [string ]struct {
336336 want string
337337 metricNames []string
338- errPrefix string
339- fail bool
338+ // expectedErrPrefix if empty, means no fail is expected for the comparison.
339+ expectedErrPrefix string
340340 }{
341341 "empty metric Names" : {
342342 want : `
@@ -382,9 +382,8 @@ func TestScrapeAndCompare(t *testing.T) {
382382
383383 some_total2{ label2 = "value2" } 1
384384 ` ,
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" ,
388387 },
389388 "one of multiple expected metric names is not scraped" : {
390389 want : `
@@ -398,9 +397,8 @@ func TestScrapeAndCompare(t *testing.T) {
398397
399398 some_total2{ label2 = "value2" } 1
400399 ` ,
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" ,
404402 },
405403 }
406404 for name , scenario := range scenarios {
@@ -412,10 +410,10 @@ func TestScrapeAndCompare(t *testing.T) {
412410 }))
413411 defer ts .Close ()
414412 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 ) {
416414 t .Errorf ("unexpected error happened: %s" , err )
417415 }
418- } else if scenario .fail {
416+ } else if scenario .expectedErrPrefix != "" {
419417 t .Errorf ("expected an error but got nil" )
420418 }
421419 })
0 commit comments