1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00
node-feature-discovery/test/e2e/e2e_test.go
Markus Lehtonen d2652cebb7 test/e2e: stop importing kubernetes test/e2e
Don't import the kubernetes tests/e2e "root" package (we still use the
test/e2e/framework). We only used the simple e2e runner function from
there so copy that over to the nfd test/e2e package. This change removes
a lot of dependencies speeding up builds.
2024-04-26 09:34:34 +03:00

99 lines
3.3 KiB
Go

/*
Copyright 2015 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 e2e
import (
"flag"
"fmt"
"os"
"testing"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"k8s.io/component-base/logs"
"k8s.io/klog/v2"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/config"
"k8s.io/kubernetes/test/e2e/framework/testfiles"
)
var (
dockerRepo = flag.String("nfd.repo", "gcr.io/k8s-staging-nfd/node-feature-discovery", "Docker repository to fetch image from")
dockerTag = flag.String("nfd.tag", "master", "Docker tag to use")
)
// handleFlags sets up all flags and parses the command line.
func handleFlags() {
config.CopyFlags(config.Flags, flag.CommandLine)
framework.RegisterCommonFlags(flag.CommandLine)
framework.RegisterClusterFlags(flag.CommandLine)
flag.Parse()
}
// must be called after flags are parsed
func dockerImage() string {
return fmt.Sprintf("%s:%s", *dockerRepo, *dockerTag)
}
func TestMain(m *testing.M) {
// Register test flags, then parse flags.
handleFlags()
framework.AfterReadingAllFlags(&framework.TestContext)
// TODO: Deprecating repo-root over time... instead just use gobindata_util.go , see #23987.
// Right now it is still needed, for example by
// test/e2e/framework/ingress/ingress_utils.go
// for providing the optional secret.yaml file and by
// test/e2e/framework/util.go for cluster/log-dump.
if framework.TestContext.RepoRoot != "" {
testfiles.AddFileSource(testfiles.RootFileSource{Root: framework.TestContext.RepoRoot})
}
os.Exit(m.Run())
}
func TestE2E(t *testing.T) {
runE2ETests(t)
}
// RunE2ETests checks configuration parameters (specified through flags) and then runs
// E2E tests using the Ginkgo runner.
// If a "report directory" is specified, one or more JUnit test reports will be
// generated in this directory, and cluster logs will also be saved.
// This function is called on each Ginkgo node in parallel mode.
func runE2ETests(t *testing.T) {
// InitLogs disables contextual logging, without a way to enable it again
// in the E2E test suite because it has no feature gates. It used to have a
// misleading --feature-gates parameter but that didn't do what users
// and developers expected (define which features the cluster supports)
// and therefore got removed.
//
// Because contextual logging is useful and should get tested, it gets
// re-enabled here unconditionally.
logs.InitLogs()
defer logs.FlushLogs()
klog.EnableContextualLogging(true)
gomega.RegisterFailHandler(framework.Fail)
// Run tests through the Ginkgo runner with output to console + JUnit for Jenkins
suiteConfig, reporterConfig := framework.CreateGinkgoConfig()
klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunID, suiteConfig.ParallelProcess)
ginkgo.RunSpecs(t, "Kubernetes e2e suite", suiteConfig, reporterConfig)
}