mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-05 13:08:07 -05:00
gtr: Add default package name to report
This commit is contained in:
parent
79753fd332
commit
77ad1709cf
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
packageName: packageName,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *ReportBuilder) flush() {
|
||||
if len(b.tests) > 0 {
|
||||
b.CreatePackage("unknown", 0)
|
||||
b.CreatePackage(b.packageName, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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":
|
||||
|
Loading…
x
Reference in New Issue
Block a user