parser/gotest: Make reportBuilder options private

This commit is contained in:
Joël Stemmer 2022-05-21 22:16:55 +01:00
parent ae7e71c599
commit f97910c4b9
2 changed files with 9 additions and 9 deletions

View File

@ -88,9 +88,9 @@ func (p *Parser) Parse(r io.Reader) (gtr.Report, error) {
// report generates a gtr.Report from the given list of events. // report generates a gtr.Report from the given list of events.
func (p *Parser) report(events []Event) gtr.Report { func (p *Parser) report(events []Event) gtr.Report {
rb := newReportBuilder() rb := newReportBuilder()
rb.PackageName = p.packageName rb.packageName = p.packageName
if p.timestampFunc != nil { if p.timestampFunc != nil {
rb.TimestampFunc = p.timestampFunc rb.timestampFunc = p.timestampFunc
} }
for _, ev := range events { for _, ev := range events {
switch ev.Type { switch ev.Type {

View File

@ -27,9 +27,9 @@ type reportBuilder struct {
output []string // output that does not belong to any test output []string // output that does not belong to any test
coverage float64 // coverage percentage coverage float64 // coverage percentage
// default values // options
PackageName string packageName string
TimestampFunc func() time.Time timestampFunc func() time.Time
} }
// newReportBuilder creates a new reportBuilder. // newReportBuilder creates a new reportBuilder.
@ -40,7 +40,7 @@ func newReportBuilder() *reportBuilder {
buildErrors: make(map[int]gtr.Error), buildErrors: make(map[int]gtr.Error),
runErrors: make(map[int]gtr.Error), runErrors: make(map[int]gtr.Error),
nextID: 1, nextID: 1,
TimestampFunc: time.Now, timestampFunc: time.Now,
} }
} }
@ -57,7 +57,7 @@ func (b *reportBuilder) newID() int {
// benchmark did not end with a summary. // benchmark did not end with a summary.
func (b *reportBuilder) flush() { func (b *reportBuilder) flush() {
if len(b.tests) > 0 || len(b.benchmarks) > 0 { if len(b.tests) > 0 || len(b.benchmarks) > 0 {
b.CreatePackage(b.PackageName, "", 0, "") b.CreatePackage(b.packageName, "", 0, "")
} }
} }
@ -175,8 +175,8 @@ func (b *reportBuilder) CreatePackage(name, result string, duration time.Duratio
Duration: duration, Duration: duration,
} }
if b.TimestampFunc != nil { if b.timestampFunc != nil {
pkg.Timestamp = b.TimestampFunc() pkg.Timestamp = b.timestampFunc()
} }
// Build errors are treated somewhat differently. Rather than having a // Build errors are treated somewhat differently. Rather than having a