Skip to content

Commit

Permalink
junit: Add timestamp for suite start time
Browse files Browse the repository at this point in the history
The junit schema defines this attribute on the testsuite.
In my case I need to import test results totally separate from the
testing pipeline since these are in two different systems. This
timestamp ensures the result processor puts the results into the right
time frame instead of assuming it just ran.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Jun 15, 2021
1 parent bdcb1a9 commit 31cc95b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/junitxml/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type JUnitTestSuite struct {
Name string `xml:"name,attr"`
Properties []JUnitProperty `xml:"properties>property,omitempty"`
TestCases []JUnitTestCase
Timestamp string `xml:"timestamp,attr"`
}

// JUnitTestCase is a single test case with its result.
Expand Down Expand Up @@ -92,6 +93,7 @@ func generate(exec *testjson.Execution, cfg Config) JUnitTestSuites {
Properties: packageProperties(version),
TestCases: packageTestCases(pkg, cfg.FormatTestCaseClassname),
Failures: len(pkg.Failed),
Timestamp: exec.Started().Format(time.RFC3339),
}
suites.Suites = append(suites.Suites, junitpkg)
}
Expand Down
4 changes: 4 additions & 0 deletions testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ func (e *Execution) end() []TestEvent {
return result
}

func (e *Execution) Started() time.Time {
return e.started
}

// newExecution returns a new Execution and records the current time as the
// time the test execution started.
func newExecution() *Execution {
Expand Down

0 comments on commit 31cc95b

Please sign in to comment.