k8s.io/kubernetes@v1.29.3/test/e2e_kubeadm/e2e_kubeadm_suite_test.go (about)

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package kubeadm
    18  
    19  import (
    20  	"flag"
    21  	"fmt"
    22  	"os"
    23  	"testing"
    24  
    25  	"github.com/onsi/ginkgo/v2"
    26  	"github.com/onsi/gomega"
    27  	"github.com/spf13/pflag"
    28  
    29  	"k8s.io/kubernetes/test/e2e/framework"
    30  	e2econfig "k8s.io/kubernetes/test/e2e/framework/config"
    31  
    32  	// reconfigure framework
    33  	_ "k8s.io/kubernetes/test/e2e/framework/debug/init"
    34  	_ "k8s.io/kubernetes/test/e2e/framework/metrics/init"
    35  	_ "k8s.io/kubernetes/test/e2e/framework/node/init"
    36  	_ "k8s.io/kubernetes/test/utils/format"
    37  )
    38  
    39  func TestMain(m *testing.M) {
    40  	// Copy go flags in TestMain, to ensure go test flags are registered (no longer available in init() as of go1.13)
    41  	e2econfig.CopyFlags(e2econfig.Flags, flag.CommandLine)
    42  	framework.RegisterCommonFlags(flag.CommandLine)
    43  	framework.RegisterClusterFlags(flag.CommandLine)
    44  	pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
    45  	pflag.Parse()
    46  	if pflag.CommandLine.NArg() > 0 {
    47  		fmt.Fprintf(os.Stderr, "unknown additional command line arguments: %s", pflag.CommandLine.Args())
    48  		os.Exit(1)
    49  	}
    50  	framework.AfterReadingAllFlags(&framework.TestContext)
    51  	os.Exit(m.Run())
    52  }
    53  
    54  func TestE2E(t *testing.T) {
    55  	gomega.RegisterFailHandler(ginkgo.Fail)
    56  	reportDir := framework.TestContext.ReportDir
    57  	if reportDir != "" {
    58  		// Create the directory if it doesn't already exists
    59  		// NOTE: junit report can be simply created by executing your tests with the new --junit-report flags instead.
    60  		if err := os.MkdirAll(reportDir, 0755); err != nil {
    61  			t.Fatalf("Failed creating report directory: %v", err)
    62  		}
    63  	}
    64  	suiteConfig, reporterConfig := framework.CreateGinkgoConfig()
    65  	ginkgo.RunSpecs(t, "E2EKubeadm suite", suiteConfig, reporterConfig)
    66  }