From 9279e9868412ad4ad4005dbdc00accc0fb5082e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=94=A6=E5=8D=97=E8=B7=AF=E4=B9=8B=E8=8A=B1?= Date: Tue, 2 Apr 2024 22:22:56 +0200 Subject: [PATCH] test: allow running functional tests for different k8s versions --- test/integration/functional_test.go | 20 +++++++++++++++++++- test/integration/main_test.go | 6 +++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index fd50dadc4d07..f924aff41d1e 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,27 @@ var mitm *StartSession var runCorpProxy = detect.GithubActionRunner() && runtime.GOOS == "linux" && !arm64Platform() +// k8s version string for functional test. +// When this variable is set, minikube will be started with the specified version for functional test +var k8sVersionString = "" + // TestFunctional are functionality tests which can safely share a profile in parallel func TestFunctional(t *testing.T) { + testFunctional(t) +} +// TestFunctionalNewestKuberentes are functionality run functional tests using NewestKubernetesVersion +func TestFunctionalNewestKuberentes(t *testing.T) { + if strings.Contains(*startArgs, "--kubernetes-version") { + t.Skip() + } + k8sVersionString = constants.NewestKubernetesVersion + t.Run("Version"+k8sVersionString, func(t *testing.T) { + testFunctional(t) + }) +} + +func testFunctional(t *testing.T) { profile := UniqueProfileName("functional") ctx, cancel := context.WithTimeout(context.Background(), Minutes(40)) defer func() { @@ -86,7 +105,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..9483705064d4 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 k8sVersionString != "" { + res = append(res, fmt.Sprintf("--kubernetes-version=%s", k8sVersionString)) + } + return res } // Target returns where the minikube binary can be found