mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-05 05:00:15 -05:00

The reportBuilder has been updated to use the ordered output collector to keep track of go test output. This makes it possible to include benchmark output in the generated report and makes sure that output is preserved when deleting subtest parents from the report.
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package gotest
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/jstemmer/go-junit-report/v2/gtr"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestGroupBenchmarksByName(t *testing.T) {
|
|
tests := []struct {
|
|
in []gtr.Benchmark
|
|
want []gtr.Benchmark
|
|
}{
|
|
{nil, nil},
|
|
{
|
|
[]gtr.Benchmark{{ID: 1, Name: "BenchmarkFailed", Result: gtr.Fail}},
|
|
[]gtr.Benchmark{{ID: 1, Name: "BenchmarkFailed", Result: gtr.Fail}},
|
|
},
|
|
{
|
|
[]gtr.Benchmark{
|
|
{ID: 1, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 10, MBPerSec: 400, BytesPerOp: 1, AllocsPerOp: 2},
|
|
{ID: 2, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 20, MBPerSec: 300, BytesPerOp: 1, AllocsPerOp: 4},
|
|
{ID: 3, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 30, MBPerSec: 200, BytesPerOp: 1, AllocsPerOp: 8},
|
|
{ID: 4, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 40, MBPerSec: 100, BytesPerOp: 5, AllocsPerOp: 2},
|
|
},
|
|
[]gtr.Benchmark{
|
|
{ID: 1, Name: "BenchmarkOne", Result: gtr.Pass, NsPerOp: 25, MBPerSec: 250, BytesPerOp: 2, AllocsPerOp: 4},
|
|
},
|
|
},
|
|
{
|
|
[]gtr.Benchmark{
|
|
{ID: 1, Name: "BenchmarkMixed", Result: gtr.Unknown},
|
|
{ID: 2, Name: "BenchmarkMixed", Result: gtr.Pass, NsPerOp: 10, MBPerSec: 400, BytesPerOp: 1, AllocsPerOp: 2},
|
|
{ID: 3, Name: "BenchmarkMixed", Result: gtr.Pass, NsPerOp: 40, MBPerSec: 100, BytesPerOp: 3, AllocsPerOp: 4},
|
|
{ID: 4, Name: "BenchmarkMixed", Result: gtr.Fail},
|
|
},
|
|
[]gtr.Benchmark{
|
|
{ID: 1, Name: "BenchmarkMixed", Result: gtr.Fail, NsPerOp: 25, MBPerSec: 250, BytesPerOp: 2, AllocsPerOp: 3},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
b := newReportBuilder()
|
|
got := b.groupBenchmarksByName(test.in)
|
|
if diff := cmp.Diff(test.want, got); diff != "" {
|
|
t.Errorf("groupBenchmarksByName result incorrect, diff (-want, +got):\n%s\n", diff)
|
|
}
|
|
}
|
|
}
|