From f226d116fd1ae970318f6409338a33db3f914747 Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Fri, 31 Jan 2020 00:00:57 -0800 Subject: [PATCH] In "go test" 1.13 and higher, you cannot call parse.Flags in init() In https://golang.org/doc/go1.13#testing 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. See: https://groups.google.com/d/msg/golang-nuts/rkCdS1EQwSM/4gbwNh0QAwAJ https://github.com/golang/go/issues/21051 https://go-review.googlesource.com/c/go/+/173722/ https://www.bountysource.com/issues/79987300-flag-provided-but-not-defined-test-timeout-go-1-13 https://golang.org/pkg/testing/#hdr-Main --- tests/asg/asg_test.go | 5 ++++- tests/autopilot/autopilot_test.go | 5 ++++- tests/basic/basic_test.go | 5 ++++- tests/drive_failure/drive_failure_test.go | 5 ++++- tests/node_decommission/node_decommission_test.go | 5 ++++- tests/reboot/reboot_test.go | 5 ++++- tests/sched/sched_test.go | 5 ++++- tests/upgrade/upgrade_test.go | 5 ++++- tests/volume_ops/volume_ops_test.go | 5 ++++- 9 files changed, 36 insertions(+), 9 deletions(-) diff --git a/tests/asg/asg_test.go b/tests/asg/asg_test.go index da41f8f9042..aefeb61d2a3 100644 --- a/tests/asg/asg_test.go +++ b/tests/asg/asg_test.go @@ -3,6 +3,7 @@ package tests import ( "fmt" "math/rand" + "os" "testing" "time" @@ -203,8 +204,10 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } func Scale(count int64) { diff --git a/tests/autopilot/autopilot_test.go b/tests/autopilot/autopilot_test.go index 1837ee3a61e..df426f9bf28 100644 --- a/tests/autopilot/autopilot_test.go +++ b/tests/autopilot/autopilot_test.go @@ -2,6 +2,7 @@ package tests import ( "fmt" + "os" "strings" "testing" "time" @@ -525,6 +526,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } diff --git a/tests/basic/basic_test.go b/tests/basic/basic_test.go index 98ec8fe7c4e..46476b3be04 100644 --- a/tests/basic/basic_test.go +++ b/tests/basic/basic_test.go @@ -3,6 +3,7 @@ package tests import ( "fmt" "math/rand" + "os" "testing" "time" @@ -444,6 +445,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } diff --git a/tests/drive_failure/drive_failure_test.go b/tests/drive_failure/drive_failure_test.go index eaf57382f5d..871e38e2391 100644 --- a/tests/drive_failure/drive_failure_test.go +++ b/tests/drive_failure/drive_failure_test.go @@ -2,6 +2,7 @@ package tests import ( "fmt" + "os" "testing" "time" @@ -122,6 +123,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } diff --git a/tests/node_decommission/node_decommission_test.go b/tests/node_decommission/node_decommission_test.go index 5aac34fbb57..d1f1fe95321 100644 --- a/tests/node_decommission/node_decommission_test.go +++ b/tests/node_decommission/node_decommission_test.go @@ -3,6 +3,7 @@ package tests import ( "fmt" "math/rand" + "os" "testing" "time" @@ -121,6 +122,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } diff --git a/tests/reboot/reboot_test.go b/tests/reboot/reboot_test.go index f4a3d1c8637..fa4a7d41dc4 100644 --- a/tests/reboot/reboot_test.go +++ b/tests/reboot/reboot_test.go @@ -2,6 +2,7 @@ package tests import ( "fmt" + "os" "testing" "time" @@ -160,6 +161,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } diff --git a/tests/sched/sched_test.go b/tests/sched/sched_test.go index e02889711af..49cc51b759a 100644 --- a/tests/sched/sched_test.go +++ b/tests/sched/sched_test.go @@ -2,6 +2,7 @@ package tests import ( "fmt" + "os" "testing" "time" @@ -83,6 +84,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } diff --git a/tests/upgrade/upgrade_test.go b/tests/upgrade/upgrade_test.go index cdb8e497924..33b7e5848f1 100644 --- a/tests/upgrade/upgrade_test.go +++ b/tests/upgrade/upgrade_test.go @@ -2,6 +2,7 @@ package tests import ( "fmt" + "os" "strings" "testing" @@ -116,6 +117,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) } diff --git a/tests/volume_ops/volume_ops_test.go b/tests/volume_ops/volume_ops_test.go index 71a86e3c15f..15e163323ff 100644 --- a/tests/volume_ops/volume_ops_test.go +++ b/tests/volume_ops/volume_ops_test.go @@ -3,6 +3,7 @@ package tests import ( "fmt" "math" + "os" "testing" . "github.com/onsi/ginkgo" @@ -167,6 +168,8 @@ var _ = AfterSuite(func() { ValidateCleanup() }) -func init() { +func TestMain(m *testing.M) { + // call flag.Parse() here if TestMain uses flags ParseFlags() + os.Exit(m.Run()) }