@@ -350,30 +350,61 @@ func TestGroupBenchmarksByName(t *testing.T) {
350
350
}
351
351
}
352
352
353
- func TestReportFailedSummary (t * testing.T ) {
354
- events := []Event {
355
- {Type : "summary" , Result : "FAIL" , Name : "package/name" , Duration : 1 * time .Millisecond },
356
- }
357
- want := gtr.Report {
358
- Packages : []gtr.Package {
359
- {
360
- Name : "package/name" ,
361
- Duration : 1 * time .Millisecond ,
362
- Timestamp : testTimestamp ,
363
- RunError : gtr.Error {
364
- Name : "package/name" ,
353
+ func TestReportSpecialCases (t * testing.T ) {
354
+ tests := []struct {
355
+ name string
356
+ events []Event
357
+ want gtr.Report
358
+ }{
359
+ {
360
+ "failed-summary-only" ,
361
+ []Event {{Type : "summary" , Result : "FAIL" , Name : "package/name" , Duration : 1 * time .Millisecond }},
362
+ gtr.Report {
363
+ Packages : []gtr.Package {
364
+ {
365
+ Name : "package/name" ,
366
+ Duration : 1 * time .Millisecond ,
367
+ Timestamp : testTimestamp ,
368
+ RunError : gtr.Error {
369
+ Name : "package/name" ,
370
+ },
371
+ },
372
+ },
373
+ },
374
+ },
375
+ {
376
+ "leftover-builderror" ,
377
+ []Event {
378
+ {Type : "build_output" , Name : "package/name" },
379
+ {Type : "output" , Data : "error message" },
380
+ },
381
+ gtr.Report {
382
+ Packages : []gtr.Package {
383
+ {
384
+ Name : "package/name" ,
385
+ Timestamp : testTimestamp ,
386
+ BuildError : gtr.Error {
387
+ ID : 1 ,
388
+ Name : "package/name" ,
389
+ Output : []string {"error message" },
390
+ },
391
+ },
365
392
},
366
393
},
367
394
},
368
395
}
369
396
370
- rb := newReportBuilder ()
371
- rb .timestampFunc = testTimestampFunc
372
- for _ , ev := range events {
373
- rb .ProcessEvent (ev )
374
- }
375
- got := rb .Build ()
376
- if diff := cmp .Diff (want , got ); diff != "" {
377
- t .Errorf ("Incorrect report created, diff (-want, +got):\n %v\n " , diff )
397
+ for _ , test := range tests {
398
+ t .Run (test .name , func (t * testing.T ) {
399
+ rb := newReportBuilder ()
400
+ rb .timestampFunc = testTimestampFunc
401
+ for _ , ev := range test .events {
402
+ rb .ProcessEvent (ev )
403
+ }
404
+ got := rb .Build ()
405
+ if diff := cmp .Diff (test .want , got ); diff != "" {
406
+ t .Errorf ("Incorrect report created, diff (-want, +got):\n %v\n " , diff )
407
+ }
408
+ })
378
409
}
379
410
}
0 commit comments