diff --git a/go-junit-report.go b/go-junit-report.go index e1a38aa..099e94d 100644 --- a/go-junit-report.go +++ b/go-junit-report.go @@ -53,7 +53,7 @@ func main() { fmt.Printf("%02d: %#v\n", i, ev) } } - report := gtr.FromEvents(events) + report := gtr.FromEvents(events, *packageName) if !*noXMLHeader { fmt.Fprintf(os.Stdout, xml.Header) diff --git a/go-junit-report_test.go b/go-junit-report_test.go index 82c6282..5773dc3 100644 --- a/go-junit-report_test.go +++ b/go-junit-report_test.go @@ -1574,12 +1574,12 @@ func TestNewOutput(t *testing.T) { } t.Run(testCase.name, func(t *testing.T) { - testNewParser(testCase.name, testCase.reportName, t) + testNewParser(testCase.name, testCase.reportName, testCase.packageName, t) }) } } -func testNewParser(input, reportFile string, t *testing.T) { +func testNewParser(input, reportFile, packageName string, t *testing.T) { file, err := os.Open("testdata/" + input) if err != nil { t.Fatal(err) @@ -1591,7 +1591,7 @@ func testNewParser(input, reportFile string, t *testing.T) { t.Fatal(err) } - report := gtr.FromEvents(events) + actual := gtr.JUnit(gtr.FromEvents(events, packageName)) actual, err := toXML(gtr.JUnit(report)) if err != nil { diff --git a/pkg/gtr/builder.go b/pkg/gtr/builder.go index 5fbdffe..94b2052 100644 --- a/pkg/gtr/builder.go +++ b/pkg/gtr/builder.go @@ -15,19 +15,23 @@ type ReportBuilder struct { nextId int // next free id lastId int // last test id // TODO: stack? output []string + + // defaults + packageName string } -func NewReportBuilder() *ReportBuilder { +func NewReportBuilder(packageName string) *ReportBuilder { return &ReportBuilder{ - tests: make(map[int]Test), - benchmarks: make(map[int]Benchmark), - nextId: 1, + tests: make(map[int]Test), + benchmarks: make(map[int]Benchmark), + nextId: 1, + packageName: packageName, } } func (b *ReportBuilder) flush() { if len(b.tests) > 0 { - b.CreatePackage("unknown", 0) + b.CreatePackage(b.packageName, 0) } } diff --git a/pkg/gtr/gtr.go b/pkg/gtr/gtr.go index cabde17..f532aac 100644 --- a/pkg/gtr/gtr.go +++ b/pkg/gtr/gtr.go @@ -59,8 +59,9 @@ type Benchmark struct { } // FromEvents creates a Report from the given list of events. -func FromEvents(events []Event) Report { - report := NewReportBuilder() +// TODO: make packageName optional option +func FromEvents(events []Event, packageName string) Report { + report := NewReportBuilder(packageName) for _, ev := range events { switch ev.Type { case "run_test":