diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index fd50dadc4d07..33a26ba1c636 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -42,6 +42,7 @@ import ( "k8s.io/minikube/pkg/drivers/kic/oci" "k8s.io/minikube/pkg/minikube/config" + "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/localpath" "k8s.io/minikube/pkg/minikube/reason" @@ -70,9 +71,39 @@ var mitm *StartSession var runCorpProxy = detect.GithubActionRunner() && runtime.GOOS == "linux" && !arm64Platform() +// versionStrings stores the version number which we want to run test on +var versionStrings = []string{ + "", + constants.NewestKubernetesVersion, +} + +var overrideVersionString = "" + // TestFunctional are functionality tests which can safely share a profile in parallel func TestFunctional(t *testing.T) { + // if --kubernetes-version has been specified then we will respect the version + if strings.Contains(*startArgs, "--kubernetes-version") { + versionStrings = []string{""} + } + + // when the version is "" (default), test will be named something like "TestFunctional/parallel/xxx" + // but when the version is specified, test will be named something like TestFunctional/Versionxxx/parallel/xxx + // by doing so, when user want to run a functional test on an existing minikube cluster, it can still use + // -test.run TestFunctional/parallel/MountCmd without triggering multiple functional tests for different versions + for _, versionString := range versionStrings { + overrideVersionString = versionString + if versionString != "" { + t.Run("Version"+versionString, func(t *testing.T) { + testFunctional(t) + }) + } else { + testFunctional(t) + } + } +} + +func testFunctional(t *testing.T) { profile := UniqueProfileName("functional") ctx, cancel := context.WithTimeout(context.Background(), Minutes(40)) defer func() { @@ -86,7 +117,6 @@ func TestFunctional(t *testing.T) { Cleanup(t, profile, cancel) }() - // Serial tests t.Run("serial", func(t *testing.T) { tests := []struct { diff --git a/test/integration/main_test.go b/test/integration/main_test.go index 051c302b2951..c213da9c81cf 100644 --- a/test/integration/main_test.go +++ b/test/integration/main_test.go @@ -116,7 +116,11 @@ func setMaxParallelism() { // StartArgs returns the arguments normally used for starting minikube func StartArgs() []string { - return strings.Split(*startArgs, " ") + res := strings.Split(*startArgs, " ") + if overrideVersionString != "" { + res = append(res, fmt.Sprintf("--kubernetes-version=%s", overrideVersionString)) + } + return res } // Target returns where the minikube binary can be found