mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-05 13:08:07 -05:00
junit: Use the timestamp from the gtr.Report when creating Testsuites
This commit is contained in:
parent
b0a9864d1e
commit
4b87b03e55
@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/jstemmer/go-junit-report/v2/pkg/junit"
|
"github.com/jstemmer/go-junit-report/v2/pkg/junit"
|
||||||
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
|
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
|
||||||
@ -94,7 +93,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hostname, _ := os.Hostname() // ignore error
|
hostname, _ := os.Hostname() // ignore error
|
||||||
testsuites := junit.CreateFromReport(report, hostname, time.Now())
|
testsuites := junit.CreateFromReport(report, hostname)
|
||||||
|
|
||||||
var out io.Writer = os.Stdout
|
var out io.Writer = os.Stdout
|
||||||
if *output != "" {
|
if *output != "" {
|
||||||
|
@ -191,7 +191,12 @@ func testReport(input, reportFile, packageName string, t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
parser := gotest.New(gotest.PackageName(packageName))
|
parser := gotest.New(
|
||||||
|
gotest.PackageName(packageName),
|
||||||
|
gotest.TimestampFunc(func() time.Time {
|
||||||
|
return time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
report, err := parser.Parse(file)
|
report, err := parser.Parse(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -204,8 +209,7 @@ func testReport(input, reportFile, packageName string, t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testTime := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)
|
actual := junit.CreateFromReport(report, "hostname")
|
||||||
actual := junit.CreateFromReport(report, "hostname", testTime)
|
|
||||||
|
|
||||||
expectedXML, err := loadTestReport(reportFile, "")
|
expectedXML, err := loadTestReport(reportFile, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -127,16 +127,17 @@ type Output struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateFromReport creates a JUnit representation of the given gtr.Report.
|
// CreateFromReport creates a JUnit representation of the given gtr.Report.
|
||||||
func CreateFromReport(report gtr.Report, hostname string, timestamp time.Time) Testsuites {
|
func CreateFromReport(report gtr.Report, hostname string) Testsuites {
|
||||||
ts := timestamp.Format(time.RFC3339)
|
|
||||||
|
|
||||||
var suites Testsuites
|
var suites Testsuites
|
||||||
for _, pkg := range report.Packages {
|
for _, pkg := range report.Packages {
|
||||||
var duration time.Duration
|
var duration time.Duration
|
||||||
suite := Testsuite{
|
suite := Testsuite{
|
||||||
Name: pkg.Name,
|
Name: pkg.Name,
|
||||||
Timestamp: ts,
|
Hostname: hostname,
|
||||||
Hostname: hostname,
|
}
|
||||||
|
|
||||||
|
if !pkg.Timestamp.IsZero() {
|
||||||
|
suite.SetTimestamp(pkg.Timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range pkg.Properties {
|
for k, v := range pkg.Properties {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user