Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tstromberg committed Oct 24, 2019
1 parent c4fc450 commit dcdac36
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 19 deletions.
13 changes: 8 additions & 5 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,14 @@ func runStart(cmd *cobra.Command, args []string) {
validateFlags(driverName)
validateUser(driverName)

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

k8sVersion, isUpgrade := getKubernetesVersion(oldConfig)
Expand Down
1 change: 1 addition & 0 deletions hack/jenkins/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ echo ""
echo ">> Starting ${E2E_BIN} at $(date)"
${SUDO_PREFIX}${E2E_BIN} \
-minikube-start-args="--vm-driver=${VM_DRIVER} ${EXTRA_START_ARGS}" \
--expected-default-driver="${EXPECTED_DEFAULT_DRIVER}" \
-test.timeout=60m \
-test.parallel=${PARALLEL_COUNT} \
-binary="${MINIKUBE_BIN}" && result=$? || result=$?
Expand Down
1 change: 1 addition & 0 deletions hack/jenkins/linux_integration_tests_kvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OS_ARCH="linux-amd64"
VM_DRIVER="kvm2"
JOB_NAME="KVM_Linux"
PARALLEL_COUNT=4
EXPECTED_DEFAULT_DRIVER="kvm2"

# Download files and set permissions
source ./common.sh
1 change: 1 addition & 0 deletions hack/jenkins/linux_integration_tests_none.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ VM_DRIVER="none"
JOB_NAME="none_Linux"
EXTRA_ARGS="--bootstrapper=kubeadm"
PARALLEL_COUNT=1
EXPECTED_DEFAULT_DRIVER="kvm2"

SUDO_PREFIX="sudo -E "
export KUBECONFIG="/root/.kube/config"
Expand Down
1 change: 1 addition & 0 deletions hack/jenkins/linux_integration_tests_virtualbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OS_ARCH="linux-amd64"
VM_DRIVER="virtualbox"
JOB_NAME="VirtualBox_Linux"
PARALLEL_COUNT=4
EXPECTED_DEFAULT_DRIVER="kvm2"

# Download files and set permissions
source ./common.sh
2 changes: 2 additions & 0 deletions hack/jenkins/osx_integration_tests_hyperkit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ JOB_NAME="HyperKit_macOS"
EXTRA_ARGS="--bootstrapper=kubeadm"
EXTRA_START_ARGS=""
PARALLEL_COUNT=3
EXPECTED_DEFAULT_DRIVER="hyperkit"


# Download files and set permissions
source common.sh
2 changes: 2 additions & 0 deletions hack/jenkins/osx_integration_tests_virtualbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ VM_DRIVER="virtualbox"
JOB_NAME="VirtualBox_macOS"
EXTRA_ARGS="--bootstrapper=kubeadm"
PARALLEL_COUNT=3
EXPECTED_DEFAULT_DRIVER="hyperkit"


# Download files and set permissions
source common.sh
2 changes: 1 addition & 1 deletion hack/jenkins/windows_integration_test_hyperv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gsutil.cmd -m cp -r gs://minikube-builds/$env:MINIKUBE_LOCATION/testdata .

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

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
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
$env:result=$lastexitcode
# If the last exit code was 0->success, x>0->error
If($env:result -eq 0){$env:status="success"}
Expand Down
2 changes: 1 addition & 1 deletion hack/jenkins/windows_integration_test_virtualbox.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gsutil.cmd -m cp -r gs://minikube-builds/$env:MINIKUBE_LOCATION/testdata .

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

out/e2e-windows-amd64.exe -minikube-start-args="--vm-driver=virtualbox" -binary=out/minikube-windows-amd64.exe -test.v -test.timeout=30m
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
$env:result=$lastexitcode
# If the last exit code was 0->success, x>0->error
If($env:result -eq 0){$env:status="success"}
Expand Down
Empty file removed test/integration/Untitled-1
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package integration

import (
"context"
"encoding/json"
"fmt"
"os"
"os/exec"
Expand All @@ -29,11 +30,12 @@ import (
"time"

"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/localpath"
)

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

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

Expand All @@ -73,17 +74,50 @@ func TestDownloadAndDeleteAll(t *testing.T) {
t.Errorf("expected the file for binary exist at %q but got error %v", fp, err)
}
}

// Checking if the default driver meets expectations
if ExpectedDefaultDriver() == "" {
t.Logf("--expected-default-driver=%q, continuing", ExpectedDefaultDriver())
return
}
rr, err := Run(t, exec.CommandContext(ctx, Target(), "profile", "list", "--output", "json"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
var ps map[string][]config.Profile
err = json.Unmarshal(rr.Stdout.Bytes(), &ps)
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}

got := ""
for _, p := range ps["valid"] {
if p.Name == profile {
got = p.Config.MachineConfig.VMDriver
}
}

if got != ExpectedDefaultDriver() {
t.Errorf("got driver %q, expected %q", got, ExpectedDefaultDriver())
}
})
}

// This is a weird place to test profile deletion, but this test is serial, and we have a profile to delete!
t.Run("DeleteAll", func(t *testing.T) {
if !CanCleanup() {
t.Skip("skipping, as cleanup is disabled")
}
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "--all"))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
})
// Delete should always succeed, even if previously partially or fully deleted.
t.Run("DeleteAlwaysSucceeds", func(t *testing.T) {
if !CanCleanup() {
t.Skip("skipping, as cleanup is disabled")
}
rr, err := Run(t, exec.CommandContext(ctx, Target(), "delete", "-p", profile))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
Expand Down
11 changes: 11 additions & 0 deletions test/integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

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

// Flags for faster local integration testing
var forceProfile = flag.String("profile", "", "force tests to run against a particular profile")
Expand Down Expand Up @@ -65,3 +66,13 @@ func NoneDriver() bool {
func HyperVDriver() bool {
return strings.Contains(*startArgs, "--vm-driver=hyperv")
}

// ExpectedDefaultDriver returns the expected default driver, if any
func ExpectedDefaultDriver() string {
return *defaultDriver
}

// CanCleanup returns if cleanup is allowed
func CanCleanup() bool {
return *cleanup
}

0 comments on commit dcdac36

Please sign in to comment.