Skip to content

Commit

Permalink
Use zero timestamp for tests and update golden
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
  • Loading branch information
cpuguy83 committed Jun 15, 2021
1 parent 31cc95b commit f2b0a2e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion internal/junitxml/report.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/junitxml/report_test.go
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"runtime"
"testing"
"time"

"gotest.tools/gotestsum/testjson"
"gotest.tools/v3/assert"
Expand All @@ -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")
}
Expand Down
8 changes: 4 additions & 4 deletions internal/junitxml/testdata/junitxml-report.golden
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite tests="0" failures="0" time="0.000000" name="github.com/gotestyourself/gotestyourself/testjson/internal/badmain">
<testsuite tests="0" failures="0" time="0.000000" name="github.com/gotestyourself/gotestyourself/testjson/internal/badmain" timestamp="0001-01-01T00:00:00Z">
<properties>
<property name="go.version" value="go7.7.7"></property>
</properties>
<testcase classname="" name="TestMain" time="0.000000">
<failure message="Failed" type="">sometimes main can exit 2&#xA;FAIL&#x9;github.com/gotestyourself/gotestyourself/testjson/internal/badmain&#x9;0.010s&#xA;</failure>
</testcase>
</testsuite>
<testsuite tests="18" failures="0" time="0.020000" name="github.com/gotestyourself/gotestyourself/testjson/internal/good">
<testsuite tests="18" failures="0" time="0.020000" name="github.com/gotestyourself/gotestyourself/testjson/internal/good" timestamp="0001-01-01T00:00:00Z">
<properties>
<property name="go.version" value="go7.7.7"></property>
</properties>
Expand All @@ -35,7 +35,7 @@
<testcase classname="github.com/gotestyourself/gotestyourself/testjson/internal/good" name="TestParallelTheSecond" time="0.010000"></testcase>
<testcase classname="github.com/gotestyourself/gotestyourself/testjson/internal/good" name="TestParallelTheFirst" time="0.010000"></testcase>
</testsuite>
<testsuite tests="28" failures="4" time="0.020000" name="github.com/gotestyourself/gotestyourself/testjson/internal/stub">
<testsuite tests="28" failures="4" time="0.020000" name="github.com/gotestyourself/gotestyourself/testjson/internal/stub" timestamp="0001-01-01T00:00:00Z">
<properties>
<property name="go.version" value="go7.7.7"></property>
</properties>
Expand Down Expand Up @@ -80,7 +80,7 @@
<testcase classname="github.com/gotestyourself/gotestyourself/testjson/internal/stub" name="TestParallelTheSecond" time="0.010000"></testcase>
<testcase classname="github.com/gotestyourself/gotestyourself/testjson/internal/stub" name="TestParallelTheFirst" time="0.010000"></testcase>
</testsuite>
<testsuite tests="0" failures="0" time="0.000000" name="gotest.tools/gotestsum/internal/empty">
<testsuite tests="0" failures="0" time="0.000000" name="gotest.tools/gotestsum/internal/empty" timestamp="0001-01-01T00:00:00Z">
<properties>
<property name="go.version" value="go7.7.7"></property>
</properties>
Expand Down

0 comments on commit f2b0a2e

Please sign in to comment.