Merge pull request #10196 from priyawadhwa/refactor-test-offline

Only run TestOffline/TestDownloadOnly for specified container runtime
pull/10219/head
Sharif Elgamal 2021-01-25 09:35:17 -08:00 committed by GitHub
commit 04ed63c1eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 136 additions and 145 deletions

View File

@ -40,14 +40,13 @@ import (
) )
func TestDownloadOnly(t *testing.T) { func TestDownloadOnly(t *testing.T) {
for _, r := range []string{"crio", "docker", "containerd"} {
t.Run(r, func(t *testing.T) {
// Stores the startup run result for later error messages // Stores the startup run result for later error messages
var rrr *RunResult var rrr *RunResult
profile := UniqueProfileName(r) profile := UniqueProfileName("download-only")
ctx, cancel := context.WithTimeout(context.Background(), Minutes(30)) ctx, cancel := context.WithTimeout(context.Background(), Minutes(30))
defer Cleanup(t, profile, cancel) defer Cleanup(t, profile, cancel)
containerRuntime := ContainerRuntime()
versions := []string{ versions := []string{
constants.OldestKubernetesVersion, constants.OldestKubernetesVersion,
@ -60,7 +59,7 @@ func TestDownloadOnly(t *testing.T) {
defer PostMortemLogs(t, profile) defer PostMortemLogs(t, profile)
// --force to avoid uid check // --force to avoid uid check
args := append([]string{"start", "-o=json", "--download-only", "-p", profile, "--force", "--alsologtostderr", fmt.Sprintf("--kubernetes-version=%s", v), fmt.Sprintf("--container-runtime=%s", r)}, StartArgs()...) args := append([]string{"start", "-o=json", "--download-only", "-p", profile, "--force", "--alsologtostderr", fmt.Sprintf("--kubernetes-version=%s", v)}, StartArgs()...)
rt, err := Run(t, exec.CommandContext(ctx, Target(), args...)) rt, err := Run(t, exec.CommandContext(ctx, Target(), args...))
if rrr == nil { if rrr == nil {
@ -89,9 +88,9 @@ func TestDownloadOnly(t *testing.T) {
// skip for none, as none driver does not have preload feature. // skip for none, as none driver does not have preload feature.
if !NoneDriver() { if !NoneDriver() {
if download.PreloadExists(v, r, true) { if download.PreloadExists(v, containerRuntime, true) {
// Just make sure the tarball path exists // Just make sure the tarball path exists
if _, err := os.Stat(download.TarballPath(v, r)); err != nil { if _, err := os.Stat(download.TarballPath(v, containerRuntime)); err != nil {
t.Errorf("failed to verify preloaded tarball file exists: %v", err) t.Errorf("failed to verify preloaded tarball file exists: %v", err)
} }
return return
@ -163,8 +162,7 @@ func TestDownloadOnly(t *testing.T) {
t.Errorf("failed to delete. args: %q: %v", rr.Command(), err) t.Errorf("failed to delete. args: %q: %v", rr.Command(), err)
} }
}) })
})
}
} }
func TestDownloadOnlyKic(t *testing.T) { func TestDownloadOnlyKic(t *testing.T) {

View File

@ -26,14 +26,10 @@ import (
"testing" "testing"
) )
// TestOffline makes sure minikube works without internet, once it the user has already cached the images, This test has to run after TestDownloadOnly! // TestOffline makes sure minikube works without internet, once it the user has already cached the images, This test has to run after TestDownloadOnly
func TestOffline(t *testing.T) { func TestOffline(t *testing.T) {
t.Run("group", func(t *testing.T) {
for _, rt := range []string{"docker", "crio", "containerd"} {
rt := rt
t.Run(rt, func(t *testing.T) {
MaybeParallel(t) MaybeParallel(t)
rt := ContainerRuntime()
if rt != "docker" && arm64Platform() { if rt != "docker" && arm64Platform() {
t.Skipf("skipping %s - only docker runtime supported on arm64. See https://github.com/kubernetes/minikube/issues/10144", t.Name()) t.Skipf("skipping %s - only docker runtime supported on arm64. See https://github.com/kubernetes/minikube/issues/10144", t.Name())
} }
@ -46,7 +42,7 @@ func TestOffline(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), Minutes(15)) ctx, cancel := context.WithTimeout(context.Background(), Minutes(15))
defer CleanupWithLogs(t, profile, cancel) defer CleanupWithLogs(t, profile, cancel)
startArgs := []string{"start", "-p", profile, "--alsologtostderr", "-v=1", "--memory=2000", "--wait=true", "--container-runtime", rt} startArgs := []string{"start", "-p", profile, "--alsologtostderr", "-v=1", "--memory=2000", "--wait=true"}
startArgs = append(startArgs, StartArgs()...) startArgs = append(startArgs, StartArgs()...)
c := exec.CommandContext(ctx, Target(), startArgs...) c := exec.CommandContext(ctx, Target(), startArgs...)
env := os.Environ() env := os.Environ()
@ -60,7 +56,4 @@ func TestOffline(t *testing.T) {
// Fatal so that we may collect logs before stop/delete steps // Fatal so that we may collect logs before stop/delete steps
t.Fatalf("%s failed: %v", rr.Command(), err) t.Fatalf("%s failed: %v", rr.Command(), err)
} }
})
}
})
} }