mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
e2e framework: move JUnit write function
This makes it possible to unit test it.
This commit is contained in:
parent
a53753575a
commit
f6cdd37046
42
test/e2e/framework/internal/junit/junit.go
Normal file
42
test/e2e/framework/internal/junit/junit.go
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package junit
|
||||
|
||||
import (
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/ginkgo/v2/reporters"
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
)
|
||||
|
||||
// WriteJUnitReport generates a JUnit file 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).
|
||||
func WriteJUnitReport(report ginkgo.Report, filename string) {
|
||||
config := reporters.JunitReportConfig{
|
||||
// Remove details for specs where we don't care.
|
||||
OmitTimelinesForSpecState: types.SpecStatePassed | types.SpecStateSkipped,
|
||||
|
||||
// Don't write <failure message="summary">. The same text is
|
||||
// also in the full text for the failure. If we were to write
|
||||
// both, then tools like kettle and spyglass would concatenate
|
||||
// the two strings and thus show duplicated information.
|
||||
OmitFailureMessageAttr: true,
|
||||
}
|
||||
|
||||
reporters.GenerateJUnitReportWithConfig(report, filename, config)
|
||||
}
|
@ -30,7 +30,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/ginkgo/v2/reporters"
|
||||
"github.com/onsi/ginkgo/v2/types"
|
||||
gomegaformat "github.com/onsi/gomega/format"
|
||||
|
||||
@ -40,6 +39,7 @@ import (
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
||||
"k8s.io/kubernetes/test/e2e/framework/internal/junit"
|
||||
"k8s.io/kubernetes/test/utils/kubeconfig"
|
||||
)
|
||||
|
||||
@ -522,32 +522,23 @@ func AfterReadingAllFlags(t *TestContextType) {
|
||||
}
|
||||
|
||||
if TestContext.ReportDir != "" {
|
||||
ginkgo.ReportAfterSuite("Kubernetes e2e JUnit report", writeJUnitReport)
|
||||
ginkgo.ReportAfterSuite("Kubernetes e2e JUnit report", func(report ginkgo.Report) {
|
||||
// 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(TestContext.ReportDir, "junit_"+TestContext.ReportPrefix+"01.xml")
|
||||
|
||||
// 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`.
|
||||
junit.WriteJUnitReport(report, junitReport)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
config := reporters.JunitReportConfig{
|
||||
// Remove details for specs where we don't care.
|
||||
OmitTimelinesForSpecState: types.SpecStatePassed | types.SpecStateSkipped,
|
||||
|
||||
// Don't write <failure message="summary">. The same text is
|
||||
// also in the full text for the failure. If we were to write
|
||||
// both, then tools like kettle and spyglass would concatenate
|
||||
// the two strings and thus show duplicated information.
|
||||
OmitFailureMessageAttr: true,
|
||||
}
|
||||
|
||||
// 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(TestContext.ReportDir, "junit_"+TestContext.ReportPrefix+"01.xml")
|
||||
reporters.GenerateJUnitReportWithConfig(report, junitReport, config)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user