From 31cc95bdd32f6d94f69dc91d16fc22f76dcfce98 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Tue, 15 Jun 2021 21:47:24 +0000 Subject: [PATCH] junit: Add timestamp for suite start time 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 --- internal/junitxml/report.go | 2 ++ testjson/execution.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/internal/junitxml/report.go b/internal/junitxml/report.go index 1b50e816..d679a8cc 100644 --- a/internal/junitxml/report.go +++ b/internal/junitxml/report.go @@ -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. @@ -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) } diff --git a/testjson/execution.go b/testjson/execution.go index 8be09395..a5c2f94c 100644 --- a/testjson/execution.go +++ b/testjson/execution.go @@ -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 {