kubernetes/test/e2e/e2e_test.go
Davanum Srinivas d1c948acdc
Add support for listing conformance tests
we print yaml, so you can use yaml tools like `yq`:
```
e2e.test --list-conformance-tests | yq r - --collect *.testname
```

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2020-04-01 10:48:53 -04:00

143 lines
4.5 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"
"math/rand"
"os"
"testing"
"time"
"gopkg.in/yaml.v2"
// Never, ever remove the line with "/ginkgo". Without it,
// the ginkgo test runner will not detect that this
// directory contains a Ginkgo test suite.
// See https://github.com/kubernetes/kubernetes/issues/74827
// "github.com/onsi/ginkgo"
"k8s.io/component-base/version"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/config"
"k8s.io/kubernetes/test/e2e/framework/testfiles"
"k8s.io/kubernetes/test/e2e/generated"
"k8s.io/kubernetes/test/utils/image"
// test sources
_ "k8s.io/kubernetes/test/e2e/apimachinery"
_ "k8s.io/kubernetes/test/e2e/apps"
_ "k8s.io/kubernetes/test/e2e/auth"
_ "k8s.io/kubernetes/test/e2e/autoscaling"
_ "k8s.io/kubernetes/test/e2e/cloud"
_ "k8s.io/kubernetes/test/e2e/common"
_ "k8s.io/kubernetes/test/e2e/instrumentation"
_ "k8s.io/kubernetes/test/e2e/kubectl"
_ "k8s.io/kubernetes/test/e2e/lifecycle"
_ "k8s.io/kubernetes/test/e2e/lifecycle/bootstrap"
_ "k8s.io/kubernetes/test/e2e/network"
_ "k8s.io/kubernetes/test/e2e/node"
_ "k8s.io/kubernetes/test/e2e/scheduling"
_ "k8s.io/kubernetes/test/e2e/servicecatalog"
_ "k8s.io/kubernetes/test/e2e/storage"
_ "k8s.io/kubernetes/test/e2e/storage/external"
_ "k8s.io/kubernetes/test/e2e/ui"
_ "k8s.io/kubernetes/test/e2e/windows"
)
var viperConfig = flag.String("viper-config", "", "The name of a viper config file (https://github.com/spf13/viper#what-is-viper). All e2e command line parameters can also be configured in such a file. May contain a path and may or may not contain the file suffix. The default is to look for an optional file with `e2e` as base name. If a file is specified explicitly, it must be present.")
// 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()
}
func TestMain(m *testing.M) {
var versionFlag bool
flag.CommandLine.BoolVar(&versionFlag, "version", false, "Displays version information.")
// Register test flags, then parse flags.
handleFlags()
// Now that we know which Viper config (if any) was chosen,
// parse it and update those options which weren't already set via command line flags
// (which have higher priority).
if err := viperizeFlags(*viperConfig, "e2e", flag.CommandLine); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if framework.TestContext.ListImages {
for _, v := range image.GetImageConfigs() {
fmt.Println(v.GetE2EImage())
}
os.Exit(0)
}
if versionFlag {
fmt.Printf("%s\n", version.Get())
os.Exit(0)
}
// Enable bindata file lookup as fallback.
testfiles.AddFileSource(testfiles.BindataFileSource{
Asset: generated.Asset,
AssetNames: generated.AssetNames,
})
if framework.TestContext.ListConformanceTests {
var tests []struct {
Testname string `yaml:"testname"`
Codename string `yaml:"codename"`
Description string `yaml:"description"`
Release string `yaml:"release"`
File string `yaml:"file"`
}
data := testfiles.ReadOrDie("test/conformance/testdata/conformance.yaml")
if err := yaml.Unmarshal(data, &tests); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := yaml.NewEncoder(os.Stdout).Encode(tests); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Exit(0)
}
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})
}
rand.Seed(time.Now().UnixNano())
os.Exit(m.Run())
}
func TestE2E(t *testing.T) {
RunE2ETests(t)
}