diff --git a/internal/junitxml/report.go b/internal/junitxml/report.go index d679a8cc..703ed619 100644 --- a/internal/junitxml/report.go +++ b/internal/junitxml/report.go @@ -66,6 +66,8 @@ type JUnitFailure struct { type Config struct { FormatTestSuiteName FormatFunc FormatTestCaseClassname FormatFunc + // This is used for tests to have a consistent timestamp + customTimestamp string } // FormatFunc converts a string from one format into another. @@ -93,7 +95,10 @@ 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), + Timestamp: cfg.customTimestamp, + } + if cfg.customTimestamp == "" { + junitpkg.Timestamp = exec.Started().Format(time.RFC3339) } suites.Suites = append(suites.Suites, junitpkg) } diff --git a/internal/junitxml/report_test.go b/internal/junitxml/report_test.go index d1240dd3..056588da 100644 --- a/internal/junitxml/report_test.go +++ b/internal/junitxml/report_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "runtime" "testing" + "time" "gotest.tools/gotestsum/testjson" "gotest.tools/v3/assert" @@ -19,7 +20,7 @@ func TestWrite(t *testing.T) { exec := createExecution(t) defer env.Patch(t, "GOVERSION", "go7.7.7")() - err := Write(out, exec, Config{}) + err := Write(out, exec, Config{customTimestamp: new(time.Time).Format(time.RFC3339)}) assert.NilError(t, err) golden.Assert(t, out.String(), "junitxml-report.golden") } diff --git a/internal/junitxml/testdata/junitxml-report.golden b/internal/junitxml/testdata/junitxml-report.golden index de9a4f17..7f10842c 100644 --- a/internal/junitxml/testdata/junitxml-report.golden +++ b/internal/junitxml/testdata/junitxml-report.golden @@ -1,6 +1,6 @@ - + @@ -8,7 +8,7 @@ sometimes main can exit 2 FAIL github.com/gotestyourself/gotestyourself/testjson/internal/badmain 0.010s - + @@ -35,7 +35,7 @@ - + @@ -80,7 +80,7 @@ - +