Skip to content

Commit 224bcb6

Browse files
test: allow running functional tests for different k8s versions
1 parent 86f5c14 commit 224bcb6

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

test/integration/functional_test.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242

4343
"k8s.io/minikube/pkg/drivers/kic/oci"
4444
"k8s.io/minikube/pkg/minikube/config"
45+
"k8s.io/minikube/pkg/minikube/constants"
4546
"k8s.io/minikube/pkg/minikube/detect"
4647
"k8s.io/minikube/pkg/minikube/localpath"
4748
"k8s.io/minikube/pkg/minikube/reason"
@@ -72,9 +73,25 @@ var runCorpProxy = detect.GithubActionRunner() && runtime.GOOS == "linux" && !ar
7273

7374
// TestFunctional are functionality tests which can safely share a profile in parallel
7475
func TestFunctional(t *testing.T) {
76+
testFunctional(t, "")
77+
}
78+
79+
// TestFunctionalNewestKuberentes are functionality run functional tests using NewestKubernetesVersion
80+
func TestFunctionalNewestKuberentes(t *testing.T) {
81+
if strings.Contains(*startArgs, "--kubernetes-version") {
82+
t.Skip()
83+
}
84+
k8sVersionString := constants.NewestKubernetesVersion
85+
t.Run("Version"+k8sVersionString, func(t *testing.T) {
86+
testFunctional(t, k8sVersionString)
87+
})
7588

89+
}
90+
91+
func testFunctional(t *testing.T, k8sVersion string) {
7692
profile := UniqueProfileName("functional")
77-
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
93+
ctx := context.WithValue(context.Background(), "k8sVersion", k8sVersion)
94+
ctx, cancel := context.WithTimeout(ctx, Minutes(40))
7895
defer func() {
7996
if !*cleanup {
8097
return
@@ -86,7 +103,6 @@ func TestFunctional(t *testing.T) {
86103

87104
Cleanup(t, profile, cancel)
88105
}()
89-
90106
// Serial tests
91107
t.Run("serial", func(t *testing.T) {
92108
tests := []struct {
@@ -965,7 +981,7 @@ func validateDryRun(ctx context.Context, t *testing.T, profile string) {
965981

966982
// docs: Run `minikube start --dry-run --memory 250MB`
967983
// Too little memory!
968-
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgs()...)
984+
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgsWithContext(ctx)...)
969985
c := exec.CommandContext(mctx, Target(), startArgs...)
970986
rr, err := Run(t, c)
971987

@@ -982,7 +998,7 @@ func validateDryRun(ctx context.Context, t *testing.T, profile string) {
982998
dctx, cancel := context.WithTimeout(ctx, timeout)
983999
defer cancel()
9841000
// docs: Run `minikube start --dry-run`
985-
startArgs = append([]string{"start", "-p", profile, "--dry-run", "--alsologtostderr", "-v=1"}, StartArgs()...)
1001+
startArgs = append([]string{"start", "-p", profile, "--dry-run", "--alsologtostderr", "-v=1"}, StartArgsWithContext(ctx)...)
9861002
c = exec.CommandContext(dctx, Target(), startArgs...)
9871003
rr, err = Run(t, c)
9881004
// docs: Make sure the command doesn't raise any error
@@ -1007,7 +1023,7 @@ func validateInternationalLanguage(ctx context.Context, t *testing.T, profile st
10071023
defer cancel()
10081024

10091025
// Too little memory!
1010-
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgs()...)
1026+
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgsWithContext(ctx)...)
10111027
c := exec.CommandContext(mctx, Target(), startArgs...)
10121028
// docs: Set environment variable `LC_ALL=fr` to enable minikube translation to French
10131029
c.Env = append(os.Environ(), "LC_ALL=fr")
@@ -2221,7 +2237,7 @@ func startMinikubeWithProxy(ctx context.Context, t *testing.T, profile string, p
22212237
memoryFlag = "--memory=6000"
22222238
}
22232239
// passing --api-server-port so later verify it didn't change in soft start.
2224-
startArgs := append([]string{"start", "-p", profile, memoryFlag, fmt.Sprintf("--apiserver-port=%d", apiPortTest), "--wait=all"}, StartArgs()...)
2240+
startArgs := append([]string{"start", "-p", profile, memoryFlag, fmt.Sprintf("--apiserver-port=%d", apiPortTest), "--wait=all"}, StartArgsWithContext(ctx)...)
22252241
c := exec.CommandContext(ctx, Target(), startArgs...)
22262242
env := os.Environ()
22272243
env = append(env, fmt.Sprintf("%s=%s", proxyEnv, addr))

test/integration/main_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ func StartArgs() []string {
119119
return strings.Split(*startArgs, " ")
120120
}
121121

122+
func StartArgsWithContext(ctx context.Context) []string {
123+
res := strings.Split(*startArgs, " ")
124+
value := ctx.Value("k8sVersion")
125+
if value != nil && value != "" {
126+
res = append(res, fmt.Sprintf("--kubernetes-version=%s", value))
127+
}
128+
return res
129+
}
130+
122131
// Target returns where the minikube binary can be found
123132
func Target() string {
124133
return *binaryPath

0 commit comments

Comments
 (0)