mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Move e2e_node flag copy into TestMain
As of go1.13, test flags like test.timeout are registered lazily. This means they are not available in package init() methods: > Testing flags are now registered in the new Init function, > which is invoked by the generated main function for the test. > As a result, testing flags are now only registered when running > a test binary, and packages that call flag.Parse during package > initialization may cause tests to fail. This moves the copy of CLI flags into TestMain, just prior to parse.
This commit is contained in:
parent
8618c09369
commit
00e1ffb4e0
@ -63,6 +63,16 @@ var systemValidateMode = flag.Bool("system-validate-mode", false, "If true, only
|
|||||||
var systemSpecFile = flag.String("system-spec-file", "", "The name of the system spec file that will be used for node conformance test. If it's unspecified or empty, the default system spec (system.DefaultSysSpec) will be used.")
|
var systemSpecFile = flag.String("system-spec-file", "", "The name of the system spec file that will be used for node conformance test. If it's unspecified or empty, the default system spec (system.DefaultSysSpec) will be used.")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
// Enable bindata file lookup as fallback.
|
||||||
|
testfiles.AddFileSource(testfiles.BindataFileSource{
|
||||||
|
Asset: generated.Asset,
|
||||||
|
AssetNames: generated.AssetNames,
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
// Copy go flags in TestMain, to ensure go test flags are registered (no longer available in init() as of go1.13)
|
||||||
e2econfig.CopyFlags(e2econfig.Flags, flag.CommandLine)
|
e2econfig.CopyFlags(e2econfig.Flags, flag.CommandLine)
|
||||||
framework.RegisterCommonFlags(flag.CommandLine)
|
framework.RegisterCommonFlags(flag.CommandLine)
|
||||||
framework.RegisterNodeFlags(flag.CommandLine)
|
framework.RegisterNodeFlags(flag.CommandLine)
|
||||||
@ -75,15 +85,6 @@ func init() {
|
|||||||
// into TestContext.
|
// into TestContext.
|
||||||
// TODO(pohly): remove RegisterNodeFlags from test_context.go enable Viper config support here?
|
// TODO(pohly): remove RegisterNodeFlags from test_context.go enable Viper config support here?
|
||||||
|
|
||||||
// Enable bindata file lookup as fallback.
|
|
||||||
testfiles.AddFileSource(testfiles.BindataFileSource{
|
|
||||||
Asset: generated.Asset,
|
|
||||||
AssetNames: generated.AssetNames,
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
pflag.Parse()
|
pflag.Parse()
|
||||||
framework.AfterReadingAllFlags(&framework.TestContext)
|
framework.AfterReadingAllFlags(&framework.TestContext)
|
||||||
|
Loading…
Reference in New Issue
Block a user