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:
Jordan Liggitt 2019-11-06 11:36:05 -05:00
parent 8618c09369
commit 00e1ffb4e0

View File

@ -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)