diff --git a/parser/gotest/event.go b/parser/gotest/event.go index 90ddded..6802c79 100644 --- a/parser/gotest/event.go +++ b/parser/gotest/event.go @@ -1,12 +1,17 @@ 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. type Event struct { Type string `json:"type"` Name string `json:"name,omitempty"` + Package string `json:"pkg,omitempty"` Result string `json:"result,omitempty"` Duration time.Duration `json:"duration,omitempty"` Data string `json:"data,omitempty"` @@ -23,3 +28,10 @@ type Event struct { BytesPerOp int64 `json:"benchmark_bytes_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 +} diff --git a/parser/gotest/gotest.go b/parser/gotest/gotest.go index 4ffda64..bc263fe 100644 --- a/parser/gotest/gotest.go +++ b/parser/gotest/gotest.go @@ -136,7 +136,7 @@ func (p *Parser) Parse(r io.Reader) (gtr.Report, error) { func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) { p.events = nil for { - line, _, err := r.ReadLine() + line, metadata, err := r.ReadLine() if err == io.EOF { break } else if err != nil { @@ -160,6 +160,7 @@ func (p *Parser) parse(r reader.LineReader) (gtr.Report, error) { } for _, ev := range evs { + ev.applyMetadata(metadata) p.events = append(p.events, ev) } }