From 00e1ffb4e015c9a033b6c1f5446e70822af4e964 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Wed, 6 Nov 2019 11:36:05 -0500 Subject: [PATCH] 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. --- test/e2e_node/e2e_node_suite_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/e2e_node/e2e_node_suite_test.go b/test/e2e_node/e2e_node_suite_test.go index 7b3cfb7136d..993086b675c 100644 --- a/test/e2e_node/e2e_node_suite_test.go +++ b/test/e2e_node/e2e_node_suite_test.go @@ -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.") 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) framework.RegisterCommonFlags(flag.CommandLine) framework.RegisterNodeFlags(flag.CommandLine) @@ -75,15 +85,6 @@ func init() { // into TestContext. // 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()) pflag.Parse() framework.AfterReadingAllFlags(&framework.TestContext)