From bf06ac33e14d5cef4a6f814d53176f3d23be2f53 Mon Sep 17 00:00:00 2001 From: Pavel Sturc Date: Fri, 3 Nov 2023 11:19:22 +0100 Subject: [PATCH 1/2] fix: utilize ginkgo junit --- go.mod | 2 +- go.sum | 18 +++++++++++---- main.go | 5 ++-- pkg/convert/convert.go | 52 +++++++++++++++++++++--------------------- 4 files changed, 43 insertions(+), 34 deletions(-) diff --git a/go.mod b/go.mod index dbca6f4..88da29c 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/redhat-appstudio-qe/junit2html go 1.19 -require github.com/jstemmer/go-junit-report/v2 v2.0.0 +require github.com/onsi/ginkgo/v2 v2.13.0 diff --git a/go.sum b/go.sum index 18a993a..dfb9b4b 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,14 @@ -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/jstemmer/go-junit-report/v2 v2.0.0 h1:bMZNO9B16VFn07tKyi4YJFIbZtVmJaa5Xakv9dcwK58= -github.com/jstemmer/go-junit-report/v2 v2.0.0/go.mod h1:mgHVr7VUo5Tn8OLVr1cKnLuEy0M92wdRntM99h7RkgQ= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= +github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= +github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= +google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/main.go b/main.go index 6671e91..8c92ea6 100644 --- a/main.go +++ b/main.go @@ -5,12 +5,12 @@ import ( "fmt" "os" - "github.com/jstemmer/go-junit-report/v2/junit" + reporters "github.com/onsi/ginkgo/v2/reporters" "github.com/redhat-appstudio-qe/junit2html/pkg/convert" ) func main() { - suites := &junit.Testsuites{} + suites := &reporters.JUnitTestSuites{} err := xml.NewDecoder(os.Stdin).Decode(suites) if err != nil { @@ -21,5 +21,4 @@ func main() { panic(err) } fmt.Println(html) - } diff --git a/pkg/convert/convert.go b/pkg/convert/convert.go index 6c46dc7..c009bcf 100644 --- a/pkg/convert/convert.go +++ b/pkg/convert/convert.go @@ -7,7 +7,7 @@ import ( "strings" "time" - "github.com/jstemmer/go-junit-report/v2/junit" + reporters "github.com/onsi/ginkgo/v2/reporters" ) //go:embed style.css @@ -15,7 +15,7 @@ var styles string var output string -func Convert(suites *junit.Testsuites) (string, error) { +func Convert(suites *reporters.JUnitTestSuites) (string, error) { output += "" output += "" output += "" @@ -24,16 +24,16 @@ func Convert(suites *junit.Testsuites) (string, error) { output += "" failures, total := 0, 0 - for _, s := range suites.Suites { + for _, s := range suites.TestSuites { failures += s.Failures - total += len(s.Testcases) + total += len(s.TestCases) } output += fmt.Sprintf("

%d of %d tests failed

\n", failures, total) - printLinkToReport(suites.Suites) - for _, s := range suites.Suites { + printLinkToReport(suites.TestSuites) + for _, s := range suites.TestSuites { if s.Failures > 0 { printSuiteHeader(s) - for _, c := range s.Testcases { + for _, c := range s.TestCases { if f := c.Failure; f != nil { printTest(s, c) } @@ -42,9 +42,9 @@ func Convert(suites *junit.Testsuites) (string, error) { printGatherLinks(s) } - for _, s := range suites.Suites { + for _, s := range suites.TestSuites { printSuiteHeader(s) - for _, c := range s.Testcases { + for _, c := range s.TestCases { if c.Failure == nil { printTest(s, c) } @@ -55,7 +55,7 @@ func Convert(suites *junit.Testsuites) (string, error) { return output, nil } -func printTest(testSuite junit.Testsuite, testCase junit.Testcase) { +func printTest(testSuite reporters.JUnitTestSuite, testCase reporters.JUnitTestCase) { id := fmt.Sprintf("%s.%s.%s", testSuite.Name, testCase.Classname, testCase.Name) class, text := "passed", "Pass" failure := testCase.Failure @@ -73,28 +73,28 @@ func printTest(testSuite junit.Testsuite, testCase junit.Testcase) { output += fmt.Sprintf("", id) output += "
\n" if failure != nil { - failure.Data = strings.ReplaceAll(failure.Data, ``, `"bool"`) + failure.Message = strings.ReplaceAll(failure.Message, ``, `"bool"`) + failure.Description = strings.ReplaceAll(failure.Description, ``, `"bool"`) output += fmt.Sprintf("
Failure message: \n\n%s
\n", failure.Message) - output += fmt.Sprintf("
Failure data: \n\n%s
\n", failure.Data) - if testCase.SystemErr != nil { - testCase.SystemErr.Data = strings.ReplaceAll(testCase.SystemErr.Data, ``, `"bool"`) - output += fmt.Sprintf("
Log: \n\n%s
\n", testCase.SystemErr.Data) + output += fmt.Sprintf("
Failure description: \n\n%s
\n", failure.Description) + if testCase.SystemErr != "" { + testCase.SystemErr = strings.ReplaceAll(testCase.SystemErr, ``, `"bool"`) + output += fmt.Sprintf("
Log: \n\n%s
\n", testCase.SystemErr) } } else if skipped != nil { output += fmt.Sprintf("
%s
\n", skipped.Message) } - d, _ := time.ParseDuration(testCase.Time) + d := time.Duration(testCase.Time * float64(time.Second)) output += fmt.Sprintf("

%v

\n", d) output += "
\n" output += "\n" - } -func printSuiteHeader(s junit.Testsuite) { +func printSuiteHeader(s reporters.JUnitTestSuite) { output += "

" output += s.Name - if s.Properties != nil { - for _, p := range *s.Properties { + if len(s.Properties.Properties) != 0 { + for _, p := range s.Properties.Properties { if strings.HasPrefix(p.Name, "coverage.") { v, _ := strconv.ParseFloat(p.Value, 32) output += fmt.Sprintf("%.0f%%\n", p.Name, v) @@ -105,9 +105,9 @@ func printSuiteHeader(s junit.Testsuite) { output += "

" } -func printGatherLinks(s junit.Testsuite) { - if s.Properties != nil { - for _, p := range *s.Properties { +func printGatherLinks(s reporters.JUnitTestSuite) { + if len(s.Properties.Properties) != 0 { + for _, p := range s.Properties.Properties { if strings.Contains(p.Name, "gather") { output += fmt.Sprintf("Link to %s artifacts\n", p.Value, p.Name) } @@ -115,10 +115,10 @@ func printGatherLinks(s junit.Testsuite) { } } -func printLinkToReport(suites []junit.Testsuite) { +func printLinkToReport(suites []reporters.JUnitTestSuite) { for _, suite := range suites { - if suite.Properties != nil { - for _, p := range *suite.Properties { + if len(suite.Properties.Properties) != 0 { + for _, p := range suite.Properties.Properties { if strings.Contains(p.Name, "html-report-link") { output += fmt.Sprintf("Having trouble viewing this report? Click here to open it in another tab\n", p.Value) } From ee01c6b4ac5e4c7339b461e3e52adad6a43a2160 Mon Sep 17 00:00:00 2001 From: Pavel Sturc Date: Fri, 3 Nov 2023 11:53:30 +0100 Subject: [PATCH 2/2] fix: test duration --- pkg/convert/convert.go | 14 ++++++++------ pkg/convert/style.css | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/convert/convert.go b/pkg/convert/convert.go index c009bcf..5f7ed3e 100644 --- a/pkg/convert/convert.go +++ b/pkg/convert/convert.go @@ -72,20 +72,22 @@ func printTest(testSuite reporters.JUnitTestSuite, testCase reporters.JUnitTestC output += fmt.Sprintf("\n", id, testCase.Name, text) output += fmt.Sprintf("", id) output += "
\n" + + d := time.Duration(testCase.Time * float64(time.Second)).Round(time.Second) + output += fmt.Sprintf("

Test duration: %v

\n", d) if failure != nil { failure.Message = strings.ReplaceAll(failure.Message, ``, `"bool"`) failure.Description = strings.ReplaceAll(failure.Description, ``, `"bool"`) output += fmt.Sprintf("
Failure message: \n\n%s
\n", failure.Message) output += fmt.Sprintf("
Failure description: \n\n%s
\n", failure.Description) - if testCase.SystemErr != "" { - testCase.SystemErr = strings.ReplaceAll(testCase.SystemErr, ``, `"bool"`) - output += fmt.Sprintf("
Log: \n\n%s
\n", testCase.SystemErr) - } } else if skipped != nil { output += fmt.Sprintf("
%s
\n", skipped.Message) } - d := time.Duration(testCase.Time * float64(time.Second)) - output += fmt.Sprintf("

%v

\n", d) + if testCase.SystemErr != "" { + testCase.SystemErr = strings.ReplaceAll(testCase.SystemErr, ``, `"bool"`) + output += fmt.Sprintf("
Log: \n\n%s
\n", testCase.SystemErr) + } + output += "
\n" output += "\n" } diff --git a/pkg/convert/style.css b/pkg/convert/style.css index c8db71c..a915b71 100644 --- a/pkg/convert/style.css +++ b/pkg/convert/style.css @@ -70,7 +70,7 @@ label { } .duration { - font-size: x-small; + font-size: medium; } div:target .expando {