Skip to content

Commit dcdac36

Browse files
committed
Add integration tests
1 parent c4fc450 commit dcdac36

12 files changed

+75
-19
lines changed

cmd/minikube/cmd/start.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,14 @@ func runStart(cmd *cobra.Command, args []string) {
298298
validateFlags(driverName)
299299
validateUser(driverName)
300300

301-
v, err := version.GetSemverVersion()
302-
if err != nil {
303-
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
304-
} else if err := driver.InstallOrUpdate(driverName, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive), viper.GetBool(autoUpdate)); err != nil {
305-
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driverName, "error": err})
301+
// No need to install a driver in download-only mode
302+
if !viper.GetBool(downloadOnly) {
303+
v, err := version.GetSemverVersion()
304+
if err != nil {
305+
out.WarningT("Error parsing minikube version: {{.error}}", out.V{"error": err})
306+
} else if err := driver.InstallOrUpdate(driverName, localpath.MakeMiniPath("bin"), v, viper.GetBool(interactive), viper.GetBool(autoUpdate)); err != nil {
307+
out.WarningT("Unable to update {{.driver}} driver: {{.error}}", out.V{"driver": driverName, "error": err})
308+
}
306309
}
307310

308311
k8sVersion, isUpgrade := getKubernetesVersion(oldConfig)

hack/jenkins/common.sh

+1
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ echo ""
258258
echo ">> Starting ${E2E_BIN} at $(date)"
259259
${SUDO_PREFIX}${E2E_BIN} \
260260
-minikube-start-args="--vm-driver=${VM_DRIVER} ${EXTRA_START_ARGS}" \
261+
--expected-default-driver="${EXPECTED_DEFAULT_DRIVER}" \
261262
-test.timeout=60m \
262263
-test.parallel=${PARALLEL_COUNT} \
263264
-binary="${MINIKUBE_BIN}" && result=$? || result=$?

hack/jenkins/linux_integration_tests_kvm.sh

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ OS_ARCH="linux-amd64"
2929
VM_DRIVER="kvm2"
3030
JOB_NAME="KVM_Linux"
3131
PARALLEL_COUNT=4
32+
EXPECTED_DEFAULT_DRIVER="kvm2"
3233

3334
# Download files and set permissions
3435
source ./common.sh

hack/jenkins/linux_integration_tests_none.sh

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ VM_DRIVER="none"
3131
JOB_NAME="none_Linux"
3232
EXTRA_ARGS="--bootstrapper=kubeadm"
3333
PARALLEL_COUNT=1
34+
EXPECTED_DEFAULT_DRIVER="kvm2"
3435

3536
SUDO_PREFIX="sudo -E "
3637
export KUBECONFIG="/root/.kube/config"

hack/jenkins/linux_integration_tests_virtualbox.sh

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ OS_ARCH="linux-amd64"
2929
VM_DRIVER="virtualbox"
3030
JOB_NAME="VirtualBox_Linux"
3131
PARALLEL_COUNT=4
32+
EXPECTED_DEFAULT_DRIVER="kvm2"
3233

3334
# Download files and set permissions
3435
source ./common.sh

hack/jenkins/osx_integration_tests_hyperkit.sh

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ JOB_NAME="HyperKit_macOS"
3232
EXTRA_ARGS="--bootstrapper=kubeadm"
3333
EXTRA_START_ARGS=""
3434
PARALLEL_COUNT=3
35+
EXPECTED_DEFAULT_DRIVER="hyperkit"
36+
3537

3638
# Download files and set permissions
3739
source common.sh

hack/jenkins/osx_integration_tests_virtualbox.sh

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ VM_DRIVER="virtualbox"
3030
JOB_NAME="VirtualBox_macOS"
3131
EXTRA_ARGS="--bootstrapper=kubeadm"
3232
PARALLEL_COUNT=3
33+
EXPECTED_DEFAULT_DRIVER="hyperkit"
34+
3335

3436
# Download files and set permissions
3537
source common.sh

hack/jenkins/windows_integration_test_hyperv.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gsutil.cmd -m cp -r gs://minikube-builds/$env:MINIKUBE_LOCATION/testdata .
1919

2020
./out/minikube-windows-amd64.exe delete
2121

22-
out/e2e-windows-amd64.exe -minikube-start-args="--vm-driver=hyperv --hyperv-virtual-switch=primary-virtual-switch" -binary=out/minikube-windows-amd64.exe -test.v -test.timeout=65m
22+
out/e2e-windows-amd64.exe -minikube-start-args="--vm-driver=hyperv --expected-default-driver=hyperv --hyperv-virtual-switch=primary-virtual-switch" -binary=out/minikube-windows-amd64.exe -test.v -test.timeout=65m
2323
$env:result=$lastexitcode
2424
# If the last exit code was 0->success, x>0->error
2525
If($env:result -eq 0){$env:status="success"}

hack/jenkins/windows_integration_test_virtualbox.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ gsutil.cmd -m cp -r gs://minikube-builds/$env:MINIKUBE_LOCATION/testdata .
1919

2020
./out/minikube-windows-amd64.exe delete
2121

22-
out/e2e-windows-amd64.exe -minikube-start-args="--vm-driver=virtualbox" -binary=out/minikube-windows-amd64.exe -test.v -test.timeout=30m
22+
out/e2e-windows-amd64.exe -minikube-start-args="--vm-driver=virtualbox --expected-default-driver=hyperv" -binary=out/minikube-windows-amd64.exe -test.v -test.timeout=30m
2323
$env:result=$lastexitcode
2424
# If the last exit code was 0->success, x>0->error
2525
If($env:result -eq 0){$env:status="success"}

test/integration/Untitled-1

Whitespace-only changes.

test/integration/a_serial_tests.go renamed to test/integration/a_serial_test.go

+46-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package integration
2020

2121
import (
2222
"context"
23+
"encoding/json"
2324
"fmt"
2425
"os"
2526
"os/exec"
@@ -29,11 +30,12 @@ import (
2930
"time"
3031

3132
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
33+
"k8s.io/minikube/pkg/minikube/config"
3234
"k8s.io/minikube/pkg/minikube/constants"
3335
"k8s.io/minikube/pkg/minikube/localpath"
3436
)
3537

36-
func TestDownloadAndDeleteAll(t *testing.T) {
38+
func TestDownloadOnly(t *testing.T) {
3739
profile := UniqueProfileName("download")
3840
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
3941
defer Cleanup(t, profile, cancel)
@@ -46,22 +48,21 @@ func TestDownloadAndDeleteAll(t *testing.T) {
4648
}
4749
for _, v := range versions {
4850
t.Run(v, func(t *testing.T) {
49-
args := append([]string{"start", "--download-only", "-p", profile, fmt.Sprintf("--kubernetes-version=%s", v)}, StartArgs()...)
51+
// Explicitly does not pass StartArgs() to test driver default
52+
// --force to avoid uid check
53+
args := []string{"start", "--download-only", "-p", profile, "--force", fmt.Sprintf("--kubernetes-version=%s", v)}
5054
_, err := Run(t, exec.CommandContext(ctx, Target(), args...))
5155
if err != nil {
5256
t.Errorf("%s failed: %v", args, err)
5357
}
5458

55-
// None driver does not cache images, so this test will fail
56-
if !NoneDriver() {
57-
imgs := images.CachedImages("", v)
58-
for _, img := range imgs {
59-
img = strings.Replace(img, ":", "_", 1) // for example kube-scheduler:v1.15.2 --> kube-scheduler_v1.15.2
60-
fp := filepath.Join(localpath.MiniPath(), "cache", "images", img)
61-
_, err := os.Stat(fp)
62-
if err != nil {
63-
t.Errorf("expected image file exist at %q but got error: %v", fp, err)
64-
}
59+
imgs := images.CachedImages("", v)
60+
for _, img := range imgs {
61+
img = strings.Replace(img, ":", "_", 1) // for example kube-scheduler:v1.15.2 --> kube-scheduler_v1.15.2
62+
fp := filepath.Join(localpath.MiniPath(), "cache", "images", img)
63+
_, err := os.Stat(fp)
64+
if err != nil {
65+
t.Errorf("expected image file exist at %q but got error: %v", fp, err)
6566
}
6667
}
6768

@@ -73,17 +74,50 @@ func TestDownloadAndDeleteAll(t *testing.T) {
7374
t.Errorf("expected the file for binary exist at %q but got error %v", fp, err)
7475
}
7576
}
77+
78+
// Checking if the default driver meets expectations
79+
if ExpectedDefaultDriver() == "" {
80+
t.Logf("--expected-default-driver=%q, continuing", ExpectedDefaultDriver())
81+
return
82+
}
83+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
84+
if err != nil {
85+
t.Errorf("%s failed: %v", rr.Args, err)
86+
}
87+
var ps map[string][]config.Profile
88+
err = json.Unmarshal(rr.Stdout.Bytes(), &ps)
89+
if err != nil {
90+
t.Errorf("%s failed: %v", rr.Args, err)
91+
}
92+
93+
got := ""
94+
for _, p := range ps["valid"] {
95+
if p.Name == profile {
96+
got = p.Config.MachineConfig.VMDriver
97+
}
98+
}
99+
100+
if got != ExpectedDefaultDriver() {
101+
t.Errorf("got driver %q, expected %q", got, ExpectedDefaultDriver())
102+
}
76103
})
77104
}
105+
78106
// This is a weird place to test profile deletion, but this test is serial, and we have a profile to delete!
79107
t.Run("DeleteAll", func(t *testing.T) {
108+
if !CanCleanup() {
109+
t.Skip("skipping, as cleanup is disabled")
110+
}
80111
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "--all"))
81112
if err != nil {
82113
t.Errorf("%s failed: %v", rr.Args, err)
83114
}
84115
})
85116
// Delete should always succeed, even if previously partially or fully deleted.
86117
t.Run("DeleteAlwaysSucceeds", func(t *testing.T) {
118+
if !CanCleanup() {
119+
t.Skip("skipping, as cleanup is disabled")
120+
}
87121
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
88122
if err != nil {
89123
t.Errorf("%s failed: %v", rr.Args, err)

test/integration/main.go

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
// General configuration: used to set the VM Driver
2929
var startArgs = flag.String("minikube-start-args", "", "Arguments to pass to minikube start")
30+
var defaultDriver = flag.String("expected-default-driver", "", "Expected default driver")
3031

3132
// Flags for faster local integration testing
3233
var forceProfile = flag.String("profile", "", "force tests to run against a particular profile")
@@ -65,3 +66,13 @@ func NoneDriver() bool {
6566
func HyperVDriver() bool {
6667
return strings.Contains(*startArgs, "--vm-driver=hyperv")
6768
}
69+
70+
// ExpectedDefaultDriver returns the expected default driver, if any
71+
func ExpectedDefaultDriver() string {
72+
return *defaultDriver
73+
}
74+
75+
// CanCleanup returns if cleanup is allowed
76+
func CanCleanup() bool {
77+
return *cleanup
78+
}

0 commit comments

Comments
 (0)