mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-05 05:00:15 -05:00
parser/gotest: Add Package to Event
This allows each event to belong to a package, if we know it in advance.
This commit is contained in:
parent
f6f9df42b9
commit
bd21d54501
@ -1,12 +1,17 @@
|
|||||||
package gotest
|
package gotest
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/jstemmer/go-junit-report/v2/parser/gotest/internal/reader"
|
||||||
|
)
|
||||||
|
|
||||||
// Event is a single event in a Go test or benchmark.
|
// Event is a single event in a Go test or benchmark.
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
Package string `json:"pkg,omitempty"`
|
||||||
Result string `json:"result,omitempty"`
|
Result string `json:"result,omitempty"`
|
||||||
Duration time.Duration `json:"duration,omitempty"`
|
Duration time.Duration `json:"duration,omitempty"`
|
||||||
Data string `json:"data,omitempty"`
|
Data string `json:"data,omitempty"`
|
||||||
@ -23,3 +28,10 @@ type Event struct {
|
|||||||
BytesPerOp int64 `json:"benchmark_bytes_per_op,omitempty"`
|
BytesPerOp int64 `json:"benchmark_bytes_per_op,omitempty"`
|
||||||
AllocsPerOp int64 `json:"benchmark_allocs_per_op,omitempty"`
|
AllocsPerOp int64 `json:"benchmark_allocs_per_op,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *Event) applyMetadata(m *reader.Metadata) {
|
||||||
|
if e == nil || m == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.Package = m.Package
|
||||||
|
}
|
||||||
|
@ -136,7 +136,7 @@ func (p *Parser) Parse(r io.Reader) (gtr.Report, error) {
|
|||||||
func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) {
|
func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) {
|
||||||
p.events = nil
|
p.events = nil
|
||||||
for {
|
for {
|
||||||
line, _, err := r.ReadLine()
|
line, metadata, err := r.ReadLine()
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@ -160,6 +160,7 @@ func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, ev := range evs {
|
for _, ev := range evs {
|
||||||
|
ev.applyMetadata(metadata)
|
||||||
p.events = append(p.events, ev)
|
p.events = append(p.events, ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user