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 16, 2024
1 parent 86f5c14 commit 981083d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions site/content/en/docs/contrib/tests.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ asserts that there are no unexpected errors displayed in minikube command output
## TestFunctional
are functionality tests which can safely share a profile in parallel

## TestFunctionalNewestKubernetes
are functionality run functional tests using NewestKubernetesVersion

#### validateNodeLabels
checks if minikube cluster is created with correct kubernetes's node label

Expand Down
28 changes: 22 additions & 6 deletions 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 @@ -72,9 +73,25 @@ var runCorpProxy = detect.GithubActionRunner() && runtime.GOOS == "linux" && !ar

// TestFunctional are functionality tests which can safely share a profile in parallel
func TestFunctional(t *testing.T) {
testFunctional(t, "")
}

// TestFunctionalNewestKubernetes are functionality run functional tests using NewestKubernetesVersion
func TestFunctionalNewestKubernetes(t *testing.T) {
if strings.Contains(*startArgs, "--kubernetes-version") {
t.Skip()
}
k8sVersionString := constants.NewestKubernetesVersion
t.Run("Version"+k8sVersionString, func(t *testing.T) {
testFunctional(t, k8sVersionString)
})

}

func testFunctional(t *testing.T, k8sVersion string) {
profile := UniqueProfileName("functional")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(40))
ctx := context.WithValue(context.Background(), "k8sVersion", k8sVersion)

Check failure on line 93 in test/integration/functional_test.go

View workflow job for this annotation

GitHub Actions / lint

context-keys-type: should not use basic type string as key in context.WithValue (revive)
ctx, cancel := context.WithTimeout(ctx, Minutes(40))
defer func() {
if !*cleanup {
return
Expand All @@ -86,7 +103,6 @@ func TestFunctional(t *testing.T) {

Cleanup(t, profile, cancel)
}()

// Serial tests
t.Run("serial", func(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -965,7 +981,7 @@ func validateDryRun(ctx context.Context, t *testing.T, profile string) {

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

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

// Too little memory!
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgs()...)
startArgs := append([]string{"start", "-p", profile, "--dry-run", "--memory", "250MB", "--alsologtostderr"}, StartArgsWithContext(ctx)...)
c := exec.CommandContext(mctx, Target(), startArgs...)
// docs: Set environment variable `LC_ALL=fr` to enable minikube translation to French
c.Env = append(os.Environ(), "LC_ALL=fr")
Expand Down Expand Up @@ -2221,7 +2237,7 @@ func startMinikubeWithProxy(ctx context.Context, t *testing.T, profile string, p
memoryFlag = "--memory=6000"
}
// passing --api-server-port so later verify it didn't change in soft start.
startArgs := append([]string{"start", "-p", profile, memoryFlag, fmt.Sprintf("--apiserver-port=%d", apiPortTest), "--wait=all"}, StartArgs()...)
startArgs := append([]string{"start", "-p", profile, memoryFlag, fmt.Sprintf("--apiserver-port=%d", apiPortTest), "--wait=all"}, StartArgsWithContext(ctx)...)
c := exec.CommandContext(ctx, Target(), startArgs...)
env := os.Environ()
env = append(env, fmt.Sprintf("%s=%s", proxyEnv, addr))
Expand Down
9 changes: 9 additions & 0 deletions test/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ func StartArgs() []string {
return strings.Split(*startArgs, " ")
}

func StartArgsWithContext(ctx context.Context) []string {
res := strings.Split(*startArgs, " ")
value := ctx.Value("k8sVersion")
if value != nil && value != "" {
res = append(res, fmt.Sprintf("--kubernetes-version=%s", value))
}
return res
}

// Target returns where the minikube binary can be found
func Target() string {
return *binaryPath
Expand Down

0 comments on commit 981083d

Please sign in to comment.