diff --git a/test/integration/a_download_only_test.go b/test/integration/a_download_only_test.go index ee45bb12ed..dcd6e1cd45 100644 --- a/test/integration/a_download_only_test.go +++ b/test/integration/a_download_only_test.go @@ -34,13 +34,13 @@ import ( "k8s.io/minikube/test/integration/util" ) -// Note this test runs before all because filename is alpahbetically first +// Note this test runs before all because filename is alphabetically first // is used to cache images and binaries used by other parallel tests to avoid redownloading. // TestDownloadOnly tests the --download-only option func TestDownloadOnly(t *testing.T) { p := profileName(t) mk := NewMinikubeRunner(t, p) - if !isTestNoneDriver() { // none driver doesnt need to be deleted + if !isTestNoneDriver(t) { // none driver doesnt need to be deleted defer mk.TearDown(t) } @@ -61,7 +61,7 @@ func TestDownloadOnly(t *testing.T) { t.Run("DownloadLatestRelease", func(t *testing.T) { dest := filepath.Join(*testdataDir, fmt.Sprintf("minikube-%s-%s-latest-stable", runtime.GOOS, runtime.GOARCH)) - err := downloadMinikubeBinary(dest, "latest") + err := downloadMinikubeBinary(t, dest, "latest") if err != nil { t.Errorf("erorr downloading the latest minikube release %v", err) } @@ -70,7 +70,8 @@ func TestDownloadOnly(t *testing.T) { // downloadMinikubeBinary downloads the minikube binary from github used by TestVersionUpgrade // acts as a test setup for TestVersionUpgrade -func downloadMinikubeBinary(dest string, version string) error { +func downloadMinikubeBinary(t *testing.T, dest string, version string) error { + t.Helper() // Grab latest release binary url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS) download := func() error { diff --git a/test/integration/containerd_test.go b/test/integration/containerd_test.go index e2541bd59d..5d018bd8ac 100644 --- a/test/integration/containerd_test.go +++ b/test/integration/containerd_test.go @@ -30,10 +30,10 @@ import ( ) func TestContainerd(t *testing.T) { - if isTestNoneDriver() { + if isTestNoneDriver(t) { t.Skip("Can't run containerd backend with none driver") } - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } @@ -42,7 +42,7 @@ func TestContainerd(t *testing.T) { func testGvisorRestart(t *testing.T) { p := profileName(t) - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } mk := NewMinikubeRunner(t, p, "--wait=false") @@ -57,13 +57,13 @@ func testGvisorRestart(t *testing.T) { t.Log("waiting for gvisor controller to come up") if err := waitForGvisorControllerRunning(p); err != nil { - t.Fatalf("waiting for gvisor controller to be up: %v", err) + t.Errorf("waiting for gvisor controller to be up: %v", err) } createUntrustedWorkload(t, p) t.Log("making sure untrusted workload is Running") if err := waitForUntrustedNginxRunning(p); err != nil { - t.Fatalf("waiting for nginx to be up: %v", err) + t.Errorf("waiting for nginx to be up: %v", err) } deleteUntrustedWorkload(t, p) @@ -76,13 +76,13 @@ func testGvisorRestart(t *testing.T) { t.Log("waiting for gvisor controller to come up") if err := waitForGvisorControllerRunning(p); err != nil { - t.Fatalf("waiting for gvisor controller to be up: %v", err) + t.Errorf("waiting for gvisor controller to be up: %v", err) } createUntrustedWorkload(t, p) t.Log("making sure untrusted workload is Running") if err := waitForUntrustedNginxRunning(p); err != nil { - t.Fatalf("waiting for nginx to be up: %v", err) + t.Errorf("waiting for nginx to be up: %v", err) } deleteUntrustedWorkload(t, p) } diff --git a/test/integration/docker_test.go b/test/integration/docker_test.go index 718a228c8a..c7d02c36a3 100644 --- a/test/integration/docker_test.go +++ b/test/integration/docker_test.go @@ -28,11 +28,11 @@ import ( ) func TestDocker(t *testing.T) { - if isTestNoneDriver() { + if isTestNoneDriver(t) { t.Skip("skipping test as none driver does not bundle docker") } p := profileName(t) - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } mk := NewMinikubeRunner(t, p, "--wait=false") diff --git a/test/integration/flags.go b/test/integration/flags.go index f37a1a534d..f8ad39211e 100644 --- a/test/integration/flags.go +++ b/test/integration/flags.go @@ -38,7 +38,7 @@ var globalArgs = flag.String("minikube-args", "", "Arguments to pass to minikube var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start") var mountArgs = flag.String("minikube-mount-args", "", "Arguments to pass to minikube mount") var testdataDir = flag.String("testdata-dir", "testdata", "the directory relative to test/integration where the testdata lives") -var disableParallel = flag.Bool("disable-parallel", false, "run the tests squentially and disable all parallel runs") +var parallel = flag.Bool("parallel", true, "run the tests in parallel, set false for run sequentially") // NewMinikubeRunner creates a new MinikubeRunner func NewMinikubeRunner(t *testing.T, profile string, extraStartArgs ...string) util.MinikubeRunner { @@ -54,33 +54,34 @@ func NewMinikubeRunner(t *testing.T, profile string, extraStartArgs ...string) u } // isTestNoneDriver checks if the current test is for none driver -func isTestNoneDriver() bool { +func isTestNoneDriver(t *testing.T) bool { + t.Helper() return strings.Contains(*startArgs, "--vm-driver=none") } // profileName chooses a profile name based on the test name // to be used in minikube and kubecontext across that test func profileName(t *testing.T) string { - if isTestNoneDriver() { + t.Helper() + if isTestNoneDriver(t) { return "minikube" } - p := t.Name() - if strings.Contains(p, "/") { // for i.e, TestFunctional/SSH returns TestFunctional - p = strings.Split(p, "/")[0] - } + p := strings.Split(t.Name(), "/")[0] // for i.e, TestFunctional/SSH returns TestFunctional if p == "TestFunctional" { return "minikube" } return p } -// toParallel deterimines if test should run in parallel or not -func toParallel() bool { - if *disableParallel { +// shouldRunInParallel deterimines if test should run in parallel or not +func shouldRunInParallel(t *testing.T) bool { + t.Helper() + if !*parallel { return false } - if isTestNoneDriver() { + if isTestNoneDriver(t) { return false } - return true + p := strings.Split(t.Name(), "/")[0] // for i.e, TestFunctional/SSH returns TestFunctional + return p != "TestFunctional" // gosimple lint: https://staticcheck.io/docs/checks#S1008 } diff --git a/test/integration/fn_mount.go b/test/integration/fn_mount.go index d8d4fe38f8..8459d8d6f8 100644 --- a/test/integration/fn_mount.go +++ b/test/integration/fn_mount.go @@ -37,7 +37,7 @@ func testMounting(t *testing.T) { if runtime.GOOS == "darwin" { t.Skip("mount tests disabled in darwin due to timeout (issue#3200)") } - if isTestNoneDriver() { + if isTestNoneDriver(t) { t.Skip("skipping test for none driver as it does not need mount") } diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 35a49bb4a0..f8b57d2097 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -29,7 +29,7 @@ func TestFunctional(t *testing.T) { if err != nil { t.Fatalf("failed to start minikube failed : %v\nstdout: %s\nstderr: %s", err, stdout, stderr) } - if !isTestNoneDriver() { // none driver doesn't need to be deleted + if !isTestNoneDriver(t) { // none driver doesn't need to be deleted defer mk.TearDown(t) } @@ -49,7 +49,7 @@ func TestFunctional(t *testing.T) { t.Run("Provisioning", testProvisioning) t.Run("Tunnel", testTunnel) - if !isTestNoneDriver() { + if !isTestNoneDriver(t) { t.Run("EnvVars", testClusterEnv) t.Run("SSH", testClusterSSH) t.Run("IngressController", testIngressController) diff --git a/test/integration/iso_test.go b/test/integration/iso_test.go index 7181d43799..94092e1b5a 100644 --- a/test/integration/iso_test.go +++ b/test/integration/iso_test.go @@ -26,7 +26,7 @@ import ( func TestISO(t *testing.T) { p := profileName(t) - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } @@ -36,7 +36,7 @@ func TestISO(t *testing.T) { if err != nil { t.Fatalf("failed to start minikube (for profile %s) %s) failed : %v\nstdout: %s\nstderr: %s", t.Name(), err, stdout, stderr) } - if !isTestNoneDriver() { // none driver doesn't need to be deleted + if !isTestNoneDriver(t) { // none driver doesn't need to be deleted defer mk.TearDown(t) } diff --git a/test/integration/persistence_test.go b/test/integration/persistence_test.go index 96f04831c8..c88e1b6cbf 100644 --- a/test/integration/persistence_test.go +++ b/test/integration/persistence_test.go @@ -27,11 +27,11 @@ import ( ) func TestPersistence(t *testing.T) { - if isTestNoneDriver() { + if isTestNoneDriver(t) { t.Skip("skipping test as none driver does not support persistence") } p := profileName(t) - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } diff --git a/test/integration/start_stop_delete_test.go b/test/integration/start_stop_delete_test.go index bfa7721eec..2d13a17069 100644 --- a/test/integration/start_stop_delete_test.go +++ b/test/integration/start_stop_delete_test.go @@ -32,12 +32,12 @@ import ( func TestStartStop(t *testing.T) { p := profileName(t) // gets profile name used for minikube and kube context - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } t.Run("group", func(t *testing.T) { - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } tests := []struct { @@ -75,14 +75,14 @@ func TestStartStop(t *testing.T) { for _, tc := range tests { n := tc.name // because similar to https://golang.org/doc/faq#closures_and_goroutines t.Run(tc.name, func(t *testing.T) { - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } pn := p + n // TestStartStopoldest mk := NewMinikubeRunner(t, pn, "--wait=false") // TODO : redundant first clause ? never happens? - if !strings.Contains(pn, "docker") && isTestNoneDriver() { + if !strings.Contains(pn, "docker") && isTestNoneDriver(t) { t.Skipf("skipping %s - incompatible with none driver", t.Name()) } diff --git a/test/integration/version_upgrade_test.go b/test/integration/version_upgrade_test.go index 777c87e84c..9170ec28aa 100644 --- a/test/integration/version_upgrade_test.go +++ b/test/integration/version_upgrade_test.go @@ -54,14 +54,19 @@ func fileExists(fname string) error { // and it tries to upgrade from the older supported k8s to news supported k8s func TestVersionUpgrade(t *testing.T) { p := profileName(t) - if toParallel() { + if shouldRunInParallel(t) { t.Parallel() } // fname is the filename for the minikube's latetest binary. this file been pre-downloaded before test by hacks/jenkins/common.sh fname := filepath.Join(*testdataDir, fmt.Sprintf("minikube-%s-%s-latest-stable", runtime.GOOS, runtime.GOARCH)) err := fileExists(fname) - if err != nil { - t.Fail() + if err != nil { // download file if it is not downloaded by other test + dest := filepath.Join(*testdataDir, fmt.Sprintf("minikube-%s-%s-latest-stable", runtime.GOOS, runtime.GOARCH)) + err := downloadMinikubeBinary(t, dest, "latest") + if err != nil { + // binary is needed for the test + t.Fatalf("erorr downloading the latest minikube release %v", err) + } } defer os.Remove(fname) diff --git a/test/integration/z_proxy_test.go b/test/integration/z_proxy_test.go index 3d1382959f..69a14be0c7 100644 --- a/test/integration/z_proxy_test.go +++ b/test/integration/z_proxy_test.go @@ -17,6 +17,8 @@ limitations under the License. */ // the name of this file starts with z intentionally to make it run last after all other tests +// the intent is to make sure os env proxy settings be done after all other tests. +// for example in the case the test proxy clean up gets killed or fails package integration import ( @@ -69,7 +71,7 @@ func TestProxy(t *testing.T) { origNP := os.Getenv("NO_PROXY") p := profileName(t) // profile name - if isTestNoneDriver() { + if isTestNoneDriver(t) { // TODO fix this later t.Skip("Skipping proxy warning for none") } @@ -96,7 +98,7 @@ func TestProxy(t *testing.T) { if err != nil { t.Errorf("Error shutting down the http proxy") } - if !isTestNoneDriver() { + if !isTestNoneDriver(t) { mk.TearDown(t) }