mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #111627 from chendave/trim_report
e2e: Trim junit reporter to adapt with testgrid
This commit is contained in:
commit
cf777ab782
@ -21,11 +21,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo/v2"
|
"github.com/onsi/ginkgo/v2"
|
||||||
|
"github.com/onsi/ginkgo/v2/reporters"
|
||||||
|
"github.com/onsi/ginkgo/v2/types"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
// Never, ever remove the line with "/ginkgo". Without it,
|
// Never, ever remove the line with "/ginkgo". Without it,
|
||||||
@ -143,10 +146,9 @@ var _ = ginkgo.ReportAfterEach(func(report ginkgo.SpecReport) {
|
|||||||
progressReporter.ProcessSpecReport(report)
|
progressReporter.ProcessSpecReport(report)
|
||||||
})
|
})
|
||||||
|
|
||||||
var _ = ginkgo.ReportAfterSuite("Kubernetes e2e suite report", func(report ginkgo.Report) {
|
// writeSpecSummaryOutput will output details about every test (name, files, lines, etc) which helps
|
||||||
var err error
|
// when documenting our tests.
|
||||||
// The DetailsRepoerter will output details about every test (name, files, lines, etc) which helps
|
func writeSpecSummaryOutput(report ginkgo.Report) {
|
||||||
// when documenting our tests.
|
|
||||||
if len(framework.TestContext.SpecSummaryOutput) <= 0 {
|
if len(framework.TestContext.SpecSummaryOutput) <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -169,16 +171,58 @@ var _ = ginkgo.ReportAfterSuite("Kubernetes e2e suite report", func(report ginkg
|
|||||||
klog.Errorf("Error in detail reporter: %v", err)
|
klog.Errorf("Error in detail reporter: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err = f.Write(b)
|
if _, err = f.Write(b); err != nil {
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Printing newline between records for easier viewing in various tools.
|
// Printing newline between records for easier viewing in various tools.
|
||||||
_, err = fmt.Fprintln(f, "")
|
if _, err = fmt.Fprintln(f, ""); err != nil {
|
||||||
if err != nil {
|
|
||||||
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
klog.Errorf("Error saving test details in detail reporter: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeJUnitReport generates a JUnit file in the e2e report directory that is
|
||||||
|
// shorter than the one normally written by `ginkgo --junit-report`. This is
|
||||||
|
// needed because the full report can become too large for tools like Spyglass
|
||||||
|
// (https://github.com/kubernetes/kubernetes/issues/111510).
|
||||||
|
//
|
||||||
|
// Users who want the full report can use `--junit-report`.
|
||||||
|
func writeJUnitReport(report ginkgo.Report) {
|
||||||
|
if framework.TestContext.ReportDir == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
trimmedReport := report
|
||||||
|
trimmedReport.SpecReports = nil
|
||||||
|
for _, specReport := range report.SpecReports {
|
||||||
|
// Remove details for any spec that hasn't failed. In Prow,
|
||||||
|
// the test output captured in build-log.txt has all of this
|
||||||
|
// information, so we don't need it in the XML.
|
||||||
|
if specReport.State != types.SpecStateFailed {
|
||||||
|
// strip the "system-error" if the testcase is not failed.
|
||||||
|
specReport.CapturedGinkgoWriterOutput = ""
|
||||||
|
// strip the "system-out" if the testcase is not failed.
|
||||||
|
specReport.CapturedStdOutErr = ""
|
||||||
|
// strip some details for tracing each steps executed by Ginkgo, this is used to build the "system-out"
|
||||||
|
// while "system-out" is not shown by Spyglass if the testcase is not failed.
|
||||||
|
specReport.ReportEntries = nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
trimmedReport.SpecReports = append(trimmedReport.SpecReports, specReport)
|
||||||
|
}
|
||||||
|
|
||||||
|
// With Ginkgo v1, we used to write one file per parallel node. Now
|
||||||
|
// Ginkgo v2 automatically merges all results into a report for us. The
|
||||||
|
// 01 suffix is kept in case that users expect files to be called
|
||||||
|
// "junit_<prefix><number>.xml".
|
||||||
|
junitReport := path.Join(framework.TestContext.ReportDir, "junit_"+framework.TestContext.ReportPrefix+"01.xml")
|
||||||
|
reporters.GenerateJUnitReport(trimmedReport, junitReport)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = ginkgo.ReportAfterSuite("Kubernetes e2e suite report", func(report ginkgo.Report) {
|
||||||
|
writeSpecSummaryOutput(report)
|
||||||
|
writeJUnitReport(report)
|
||||||
})
|
})
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -356,14 +355,6 @@ func CreateGinkgoConfig() (types.SuiteConfig, types.ReporterConfig) {
|
|||||||
suiteConfig.RandomizeAllSpecs = true
|
suiteConfig.RandomizeAllSpecs = true
|
||||||
// Turn on verbose by default to get spec names
|
// Turn on verbose by default to get spec names
|
||||||
reporterConfig.Verbose = true
|
reporterConfig.Verbose = true
|
||||||
// Enable JUnit output to the result directory, but only if not already specified
|
|
||||||
// via -junit-report.
|
|
||||||
if reporterConfig.JUnitReport == "" && TestContext.ReportDir != "" {
|
|
||||||
// With Ginkgo v1, we used to write one file per parallel node. Now Ginkgo v2 automatically
|
|
||||||
// merges all results into a single file for us. The 01 suffix is kept in case that users
|
|
||||||
// expect files to be called "junit_<prefix><number>.xml".
|
|
||||||
reporterConfig.JUnitReport = path.Join(TestContext.ReportDir, "junit_"+TestContext.ReportPrefix+"01.xml")
|
|
||||||
}
|
|
||||||
// Disable skipped tests unless they are explicitly requested.
|
// Disable skipped tests unless they are explicitly requested.
|
||||||
if len(suiteConfig.FocusStrings) == 0 && len(suiteConfig.SkipStrings) == 0 {
|
if len(suiteConfig.FocusStrings) == 0 && len(suiteConfig.SkipStrings) == 0 {
|
||||||
suiteConfig.SkipStrings = []string{`\[Flaky\]|\[Feature:.+\]`}
|
suiteConfig.SkipStrings = []string{`\[Flaky\]|\[Feature:.+\]`}
|
||||||
|
Loading…
Reference in New Issue
Block a user