diff --git a/go-junit-report.go b/go-junit-report.go index 099e94d..2ce2921 100644 --- a/go-junit-report.go +++ b/go-junit-report.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "os" + "time" "github.com/jstemmer/go-junit-report/v2/pkg/gtr" "github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest" @@ -55,13 +56,16 @@ func main() { } report := gtr.FromEvents(events, *packageName) + hostname, _ := os.Hostname() // ignore error + testsuites := gtr.JUnit(report, hostname, time.Now()) + if !*noXMLHeader { fmt.Fprintf(os.Stdout, xml.Header) } enc := xml.NewEncoder(os.Stdout) enc.Indent("", "\t") - if err := enc.Encode(gtr.JUnit(report)); err != nil { + if err := enc.Encode(testsuites); err != nil { fmt.Fprintf(os.Stderr, "Error writing XML: %s\n", err) os.Exit(1) } diff --git a/go-junit-report_test.go b/go-junit-report_test.go index 10b2d27..2b718e3 100644 --- a/go-junit-report_test.go +++ b/go-junit-report_test.go @@ -11,6 +11,7 @@ import ( "strconv" "strings" "testing" + "time" "github.com/jstemmer/go-junit-report/v2/pkg/gtr" "github.com/jstemmer/go-junit-report/v2/pkg/junit" @@ -198,7 +199,8 @@ func testReport(input, reportFile, packageName string, t *testing.T) { } } - actual := gtr.JUnit(gtr.FromEvents(events, packageName)) + testTime := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) + actual := gtr.JUnit(gtr.FromEvents(events, packageName), "hostname", testTime) // Remove any new properties for backwards compatibility actual = dropNewProperties(actual) diff --git a/pkg/gtr/gtr.go b/pkg/gtr/gtr.go index ad1f86c..ccc381b 100644 --- a/pkg/gtr/gtr.go +++ b/pkg/gtr/gtr.go @@ -103,11 +103,17 @@ func FromEvents(events []Event, packageName string) Report { } // JUnit converts the given report to a collection of JUnit Testsuites. -func JUnit(report Report) junit.Testsuites { +func JUnit(report Report, hostname string, now time.Time) junit.Testsuites { + timestamp := now.Format(time.RFC3339) + var suites junit.Testsuites for _, pkg := range report.Packages { var duration time.Duration - suite := junit.Testsuite{Name: pkg.Name} + suite := junit.Testsuite{ + Name: pkg.Name, + Timestamp: timestamp, + Hostname: hostname, + } if pkg.Coverage > 0 { suite.AddProperty("coverage.statements.pct", fmt.Sprintf("%.2f", pkg.Coverage)) diff --git a/testdata/01-report.xml b/testdata/01-report.xml index 1e61495..3f25be8 100644 --- a/testdata/01-report.xml +++ b/testdata/01-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/02-report.xml b/testdata/02-report.xml index 665e9ac..f6b988a 100644 --- a/testdata/02-report.xml +++ b/testdata/02-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/03-report.xml b/testdata/03-report.xml index c7e693d..ba8b6ef 100644 --- a/testdata/03-report.xml +++ b/testdata/03-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/04-report.xml b/testdata/04-report.xml index 6f08d5f..24d00ba 100644 --- a/testdata/04-report.xml +++ b/testdata/04-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/05-report.xml b/testdata/05-report.xml index bac9b06..659dbda 100644 --- a/testdata/05-report.xml +++ b/testdata/05-report.xml @@ -1,5 +1,5 @@ - + diff --git a/testdata/06-report.xml b/testdata/06-report.xml index d47c5a0..ce72dbc 100644 --- a/testdata/06-report.xml +++ b/testdata/06-report.xml @@ -1,5 +1,5 @@ - + diff --git a/testdata/07-report.xml b/testdata/07-report.xml index 32768f1..cffa9a5 100644 --- a/testdata/07-report.xml +++ b/testdata/07-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/08-report.xml b/testdata/08-report.xml index 379c858..78c39b4 100644 --- a/testdata/08-report.xml +++ b/testdata/08-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/09-report.xml b/testdata/09-report.xml index 93102d1..e0db150 100644 --- a/testdata/09-report.xml +++ b/testdata/09-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/10-report.xml b/testdata/10-report.xml index 58e513c..1a0b494 100644 --- a/testdata/10-report.xml +++ b/testdata/10-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/11-report.xml b/testdata/11-report.xml index aa022c4..b45e7b4 100644 --- a/testdata/11-report.xml +++ b/testdata/11-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/12-report.xml b/testdata/12-report.xml index 1153361..a834ab4 100644 --- a/testdata/12-report.xml +++ b/testdata/12-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/13-report.xml b/testdata/13-report.xml index 9b472f6..d8090d8 100644 --- a/testdata/13-report.xml +++ b/testdata/13-report.xml @@ -1,18 +1,18 @@ - + - + - + @@ -20,7 +20,7 @@ failing1/failing_test.go:15: undefined: x - + @@ -28,7 +28,7 @@ failing2/another_failing_test.go:20: undefined: y - + diff --git a/testdata/14-report.xml b/testdata/14-report.xml index 9ffb0a4..913ad72 100644 --- a/testdata/14-report.xml +++ b/testdata/14-report.xml @@ -1,6 +1,6 @@ - + @@ -8,7 +8,7 @@ panic: init stacktrace - + diff --git a/testdata/15-report.xml b/testdata/15-report.xml index 4ffe374..7c5dfe2 100644 --- a/testdata/15-report.xml +++ b/testdata/15-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/16-report.xml b/testdata/16-report.xml index 4890592..b1a033b 100644 --- a/testdata/16-report.xml +++ b/testdata/16-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/17-report.xml b/testdata/17-report.xml index a47279f..fe86ca2 100644 --- a/testdata/17-report.xml +++ b/testdata/17-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/18-report.xml b/testdata/18-report.xml index 58e513c..f9bb03b 100644 --- a/testdata/18-report.xml +++ b/testdata/18-report.xml @@ -1,6 +1,6 @@ - + @@ -8,7 +8,7 @@ - + diff --git a/testdata/19-report.xml b/testdata/19-report.xml index 1e61495..3f25be8 100644 --- a/testdata/19-report.xml +++ b/testdata/19-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/20-report.xml b/testdata/20-report.xml index 7159365..0d2989b 100644 --- a/testdata/20-report.xml +++ b/testdata/20-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/21-report.xml b/testdata/21-report.xml index 889b6c9..3b74bec 100644 --- a/testdata/21-report.xml +++ b/testdata/21-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/22-report.xml b/testdata/22-report.xml index 2fb4073..1225f46 100644 --- a/testdata/22-report.xml +++ b/testdata/22-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/23-report.xml b/testdata/23-report.xml index 3db4f13..7f3217b 100644 --- a/testdata/23-report.xml +++ b/testdata/23-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/24-report.xml b/testdata/24-report.xml index 9dba7e2..3d140ff 100644 --- a/testdata/24-report.xml +++ b/testdata/24-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/25-report.xml b/testdata/25-report.xml index 92c5483..2c5edab 100644 --- a/testdata/25-report.xml +++ b/testdata/25-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/26-report.xml b/testdata/26-report.xml index fc537de..d7772a9 100644 --- a/testdata/26-report.xml +++ b/testdata/26-report.xml @@ -1,13 +1,13 @@ - + - + diff --git a/testdata/27-report.xml b/testdata/27-report.xml index e478bdf..af20f9c 100644 --- a/testdata/27-report.xml +++ b/testdata/27-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/28-report.xml b/testdata/28-report.xml index 1d7b6e5..425b7ff 100644 --- a/testdata/28-report.xml +++ b/testdata/28-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/29-report.xml b/testdata/29-report.xml index 8d393e6..fd1ed84 100644 --- a/testdata/29-report.xml +++ b/testdata/29-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/30-report.xml b/testdata/30-report.xml index b4787f5..fb9d466 100644 --- a/testdata/30-report.xml +++ b/testdata/30-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/31-report.xml b/testdata/31-report.xml index 9b472f6..d8090d8 100644 --- a/testdata/31-report.xml +++ b/testdata/31-report.xml @@ -1,18 +1,18 @@ - + - + - + @@ -20,7 +20,7 @@ failing1/failing_test.go:15: undefined: x - + @@ -28,7 +28,7 @@ failing2/another_failing_test.go:20: undefined: y - + diff --git a/testdata/32-report.xml b/testdata/32-report.xml index 16cb2f8..2d8411f 100644 --- a/testdata/32-report.xml +++ b/testdata/32-report.xml @@ -1,6 +1,6 @@ - + diff --git a/testdata/33-report.xml b/testdata/33-report.xml index 79c2327..10cea88 100644 --- a/testdata/33-report.xml +++ b/testdata/33-report.xml @@ -1,6 +1,6 @@ - +