mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 18:28:13 +00:00 
			
		
		
		
	Custom reporter of Junit report is no longer needed
Ginkgo is now writing the JUnit file itself. The -report-dir parameter is used as fallback for enabling JUnit output in case that users haven't migrated to the new -junit-report parameter. Co-authored-by: Patrick Ohly <patrick.ohly@intel.com> Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
		| @@ -22,7 +22,6 @@ import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
| 	"path" | ||||
| 	"path/filepath" | ||||
| 	"strings" | ||||
| 	"testing" | ||||
| @@ -31,8 +30,6 @@ import ( | ||||
| 	"k8s.io/klog/v2" | ||||
|  | ||||
| 	"github.com/onsi/ginkgo/v2" | ||||
| 	"github.com/onsi/ginkgo/v2/config" | ||||
| 	"github.com/onsi/ginkgo/v2/reporters" | ||||
| 	"github.com/onsi/gomega" | ||||
|  | ||||
| 	appsv1 "k8s.io/api/apps/v1" | ||||
| @@ -106,14 +103,12 @@ func RunE2ETests(t *testing.T) { | ||||
| 	gomega.RegisterFailHandler(framework.Fail) | ||||
|  | ||||
| 	// Run tests through the Ginkgo runner with output to console + JUnit for Jenkins | ||||
| 	var r []ginkgo.Reporter | ||||
| 	if framework.TestContext.ReportDir != "" { | ||||
| 		// TODO: we should probably only be trying to create this directory once | ||||
| 		// rather than once-per-Ginkgo-node. | ||||
| 		// NOTE: junit report can be simply created by executing your tests with the new --junit-report flags instead. | ||||
| 		if err := os.MkdirAll(framework.TestContext.ReportDir, 0755); err != nil { | ||||
| 			klog.Errorf("Failed creating report directory: %v", err) | ||||
| 		} else { | ||||
| 			r = append(r, reporters.NewJUnitReporter(path.Join(framework.TestContext.ReportDir, fmt.Sprintf("junit_%v%02d.xml", framework.TestContext.ReportPrefix, config.GinkgoConfig.ParallelNode)))) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -24,6 +24,7 @@ import ( | ||||
| 	"fmt" | ||||
| 	"math" | ||||
| 	"os" | ||||
| 	"path" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| @@ -293,7 +294,7 @@ func RegisterCommonFlags(flags *flag.FlagSet) { | ||||
|  | ||||
| 	flags.StringVar(&TestContext.Host, "host", "", fmt.Sprintf("The host, or apiserver, to connect to. Will default to %s if this argument and --kubeconfig are not set.", defaultHost)) | ||||
| 	flags.StringVar(&TestContext.ReportPrefix, "report-prefix", "", "Optional prefix for JUnit XML reports. Default is empty, which doesn't prepend anything to the default name.") | ||||
| 	flags.StringVar(&TestContext.ReportDir, "report-dir", "", "Path to the directory where the JUnit XML reports should be saved. Default is empty, which doesn't generate these reports.") | ||||
| 	flags.StringVar(&TestContext.ReportDir, "report-dir", "", "Path to the directory where the JUnit XML reports and other tests results should be saved. Default is empty, which doesn't generate these reports. If ginkgo's -junit-report parameter is used, that parameter instead of -report-dir determines the location of a single JUnit report.") | ||||
| 	flags.StringVar(&TestContext.ContainerRuntimeEndpoint, "container-runtime-endpoint", "unix:///var/run/containerd/containerd.sock", "The container runtime endpoint of cluster VM instances.") | ||||
| 	flags.StringVar(&TestContext.ContainerRuntimeProcessName, "container-runtime-process-name", "dockerd", "The name of the container runtime process.") | ||||
| 	flags.StringVar(&TestContext.ContainerRuntimePidFile, "container-runtime-pid-file", "/var/run/docker.pid", "The pid file of the container runtime.") | ||||
| @@ -328,6 +329,14 @@ func CreateGinkgoConfig() (types.SuiteConfig, types.ReporterConfig) { | ||||
| 	suiteConfig.RandomizeAllSpecs = true | ||||
| 	// Turn on verbose by default to get spec names | ||||
| 	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. | ||||
| 	if len(suiteConfig.FocusStrings) == 0 && len(suiteConfig.SkipStrings) == 0 { | ||||
| 		suiteConfig.SkipStrings = []string{`\[Flaky\]|\[Feature:.+\]`} | ||||
|   | ||||
| @@ -18,17 +18,13 @@ package kubeadm | ||||
|  | ||||
| import ( | ||||
| 	"flag" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/onsi/ginkgo/v2" | ||||
| 	"github.com/onsi/ginkgo/v2/config" | ||||
| 	"github.com/onsi/gomega" | ||||
| 	"github.com/spf13/pflag" | ||||
|  | ||||
| 	morereporters "github.com/onsi/ginkgo/v2/reporters" | ||||
| 	"k8s.io/kubernetes/test/e2e/framework" | ||||
| 	e2econfig "k8s.io/kubernetes/test/e2e/framework/config" | ||||
| ) | ||||
| @@ -46,17 +42,12 @@ func TestMain(m *testing.M) { | ||||
|  | ||||
| func TestE2E(t *testing.T) { | ||||
| 	gomega.RegisterFailHandler(ginkgo.Fail) | ||||
| 	reporters := []ginkgo.Reporter{} | ||||
| 	reportDir := framework.TestContext.ReportDir | ||||
| 	if reportDir != "" { | ||||
| 		// Create the directory if it doesn't already exists | ||||
| 		// NOTE: junit report can be simply created by executing your tests with the new --junit-report flags instead. | ||||
| 		if err := os.MkdirAll(reportDir, 0755); err != nil { | ||||
| 			t.Fatalf("Failed creating report directory: %v", err) | ||||
| 		} else { | ||||
| 			// Configure a junit reporter to write to the directory | ||||
| 			junitFile := fmt.Sprintf("junit_%s_%02d.xml", framework.TestContext.ReportPrefix, config.GinkgoConfig.ParallelNode) | ||||
| 			junitPath := filepath.Join(reportDir, junitFile) | ||||
| 			reporters = append(reporters, morereporters.NewJUnitReporter(junitPath)) | ||||
| 		} | ||||
| 	} | ||||
| 	suiteConfig, reporterConfig := framework.CreateGinkgoConfig() | ||||
|   | ||||
| @@ -31,7 +31,6 @@ import ( | ||||
| 	"math/rand" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
| 	"path" | ||||
| 	"syscall" | ||||
| 	"testing" | ||||
| 	"time" | ||||
| @@ -55,8 +54,6 @@ import ( | ||||
| 	system "k8s.io/system-validators/validators" | ||||
|  | ||||
| 	"github.com/onsi/ginkgo/v2" | ||||
| 	"github.com/onsi/ginkgo/v2/config" | ||||
| 	morereporters "github.com/onsi/ginkgo/v2/reporters" | ||||
| 	"github.com/onsi/gomega" | ||||
| 	"github.com/spf13/pflag" | ||||
| 	"k8s.io/klog/v2" | ||||
| @@ -179,17 +176,12 @@ func TestE2eNode(t *testing.T) { | ||||
|  | ||||
| 	// We're not running in a special mode so lets run tests. | ||||
| 	gomega.RegisterFailHandler(ginkgo.Fail) | ||||
| 	reporters := []ginkgo.Reporter{} | ||||
| 	reportDir := framework.TestContext.ReportDir | ||||
| 	if reportDir != "" { | ||||
| 		// Create the directory if it doesn't already exist | ||||
| 		// NOTE: junit report can be simply created by executing your tests with the new --junit-report flags instead. | ||||
| 		if err := os.MkdirAll(reportDir, 0755); err != nil { | ||||
| 			klog.Errorf("Failed creating report directory: %v", err) | ||||
| 		} else { | ||||
| 			// Configure a junit reporter to write to the directory | ||||
| 			junitFile := fmt.Sprintf("junit_%s_%02d.xml", framework.TestContext.ReportPrefix, config.GinkgoConfig.ParallelNode) | ||||
| 			junitPath := path.Join(reportDir, junitFile) | ||||
| 			reporters = append(reporters, morereporters.NewJUnitReporter(junitPath)) | ||||
| 		} | ||||
| 	} | ||||
| 	suiteConfig, reporterConfig := framework.CreateGinkgoConfig() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Dave Chen
					Dave Chen