Skip to content

Commit

Permalink
test: allow running functional tests for different k8s versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeProgrammer committed Apr 2, 2024
1 parent 86f5c14 commit 2d03356
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
32 changes: 31 additions & 1 deletion test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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() {
Expand All @@ -86,7 +117,6 @@ func TestFunctional(t *testing.T) {

Cleanup(t, profile, cancel)
}()

// Serial tests
t.Run("serial", func(t *testing.T) {
tests := []struct {
Expand Down
6 changes: 5 additions & 1 deletion test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d03356

Please sign in to comment.