1
1
package gotest
2
2
3
3
import (
4
+ "fmt"
4
5
"testing"
5
6
"time"
6
7
7
8
"github.com/jstemmer/go-junit-report/v2/gtr"
9
+ "github.com/jstemmer/go-junit-report/v2/parser/gotest/internal/collector"
8
10
9
11
"github.com/google/go-cmp/cmp"
10
12
)
@@ -236,6 +238,11 @@ func TestSubtestModes(t *testing.T) {
236
238
}
237
239
238
240
func TestGroupBenchmarksByName (t * testing.T ) {
241
+ output := collector .New ()
242
+ for i := 1 ; i <= 4 ; i ++ {
243
+ output .AppendToID (i , fmt .Sprintf ("output-%d" , i ))
244
+ }
245
+
239
246
tests := []struct {
240
247
name string
241
248
in []gtr.Test
@@ -245,7 +252,7 @@ func TestGroupBenchmarksByName(t *testing.T) {
245
252
{
246
253
"one failing benchmark" ,
247
254
[]gtr.Test {{ID : 1 , Name : "BenchmarkFailed" , Result : gtr .Fail , Data : map [string ]interface {}{}}},
248
- []gtr.Test {{ID : 1 , Name : "BenchmarkFailed" , Result : gtr .Fail , Data : map [string ]interface {}{}}},
255
+ []gtr.Test {{ID : 1 , Name : "BenchmarkFailed" , Result : gtr .Fail , Output : [] string { "output-1" }, Data : map [string ]interface {}{}}},
249
256
},
250
257
{
251
258
"four passing benchmarks" ,
@@ -256,7 +263,7 @@ func TestGroupBenchmarksByName(t *testing.T) {
256
263
{ID : 4 , Name : "BenchmarkOne" , Result : gtr .Pass , Data : map [string ]interface {}{key : Benchmark {NsPerOp : 40 , MBPerSec : 100 , BytesPerOp : 5 , AllocsPerOp : 2 }}},
257
264
},
258
265
[]gtr.Test {
259
- {ID : 1 , Name : "BenchmarkOne" , Result : gtr .Pass , Data : map [string ]interface {}{key : Benchmark {NsPerOp : 25 , MBPerSec : 250 , BytesPerOp : 2 , AllocsPerOp : 4 }}},
266
+ {ID : 1 , Name : "BenchmarkOne" , Result : gtr .Pass , Output : [] string { "output-1" , "output-2" , "output-3" , "output-4" }, Data : map [string ]interface {}{key : Benchmark {NsPerOp : 25 , MBPerSec : 250 , BytesPerOp : 2 , AllocsPerOp : 4 }}},
260
267
},
261
268
},
262
269
{
@@ -268,15 +275,14 @@ func TestGroupBenchmarksByName(t *testing.T) {
268
275
{ID : 4 , Name : "BenchmarkMixed" , Result : gtr .Fail },
269
276
},
270
277
[]gtr.Test {
271
- {ID : 1 , Name : "BenchmarkMixed" , Result : gtr .Fail , Data : map [string ]interface {}{key : Benchmark {NsPerOp : 25 , MBPerSec : 250 , BytesPerOp : 2 , AllocsPerOp : 3 }}},
278
+ {ID : 1 , Name : "BenchmarkMixed" , Result : gtr .Fail , Output : [] string { "output-1" , "output-2" , "output-3" , "output-4" }, Data : map [string ]interface {}{key : Benchmark {NsPerOp : 25 , MBPerSec : 250 , BytesPerOp : 2 , AllocsPerOp : 3 }}},
272
279
},
273
280
},
274
281
}
275
282
276
283
for _ , test := range tests {
277
284
t .Run (test .name , func (t * testing.T ) {
278
- b := newReportBuilder ()
279
- got := b .groupBenchmarksByName (test .in )
285
+ got := groupBenchmarksByName (test .in , output )
280
286
if diff := cmp .Diff (test .want , got ); diff != "" {
281
287
t .Errorf ("groupBenchmarksByName result incorrect, diff (-want, +got):\n %s\n " , diff )
282
288
}
0 commit comments