From 71857f42881a38e30796c6c0ffeb701e151939e2 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 26 Nov 2019 16:19:29 -0800 Subject: [PATCH] organize cache functional test --- test/integration/functional_test.go | 65 +++++++++++++++++------------ 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 870e68dfcf..f7f5207522 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -313,36 +313,47 @@ func validateCacheCmd(ctx context.Context, t *testing.T, profile string) { if NoneDriver() { t.Skipf("skipping: cache unsupported by none") } - for _, img := range []string{"busybox", "busybox:1.28.4-glibc", "k8s.gcr.io/pause:latest"} { - _, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cache", "add", img)) - if err != nil { - t.Errorf("failed to add %q to cache", img) - } - } + t.Run("cache", func(t *testing.T) { + t.Run("add", func(t *testing.T) { + for _, img := range []string{"busybox", "busybox:1.28.4-glibc", "k8s.gcr.io/pause:latest"} { + _, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cache", "add", img)) + if err != nil { + t.Errorf("Failed to cache image %q", img) + } + } + }) + t.Run("delete", func(t *testing.T) { + _, err := Run(t, exec.CommandContext(ctx, Target(), "cache", "delete", "busybox:1.28.4-glibc")) + if err != nil { + t.Errorf("failed to delete image busybox:1.28.4-glibc from cache: %v", err) + } + }) - rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "docker", "images")) - if err != nil { - t.Errorf("failed to get docker images through ssh %v", err) + t.Run("list", func(t *testing.T) { + rr, err := Run(t, exec.CommandContext(ctx, Target(), "cache", "list")) + if err != nil { + t.Errorf("cache list failed: %v", err) + } + if !strings.Contains(rr.Output(), "k8s.gcr.io/pause") { + t.Errorf("cache list did not include k8s.gcr.io/pause") + } + if strings.Contains(rr.Output(), "busybox:1.28.4-glibc") { + t.Errorf("cache list should not include busybox:1.28.4-glibc") + } + }) - } - if !strings.Contains(rr.Output(), "busybox:1.28.4-glibc") { - t.Errorf("expected busybox:1.28.4-glibc to be loaded by docker inside minikube node. but got %s", rr.Output()) - } - _, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cache", "delete", "busybox:1.28.4-glibc")) - if err != nil { - t.Errorf("failed to delete image busybox:1.28.4-glibc from cache: %v", err) - } + t.Run("verify cache inside node", func(t *testing.T) { + rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "docker", "images")) + if err != nil { + t.Errorf("failed to get docker images through ssh %v", err) + } - rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "cache", "list")) - if err != nil { - t.Errorf("cache list failed: %v", err) - } - if !strings.Contains(rr.Output(), "k8s.gcr.io/pause") { - t.Errorf("cache list did not include k8s.gcr.io/pause") - } - if strings.Contains(rr.Output(), "busybox:1.28.4-glibc") { - t.Errorf("cache list should not include busybox:1.28.4-glibc") - } + if !strings.Contains(rr.Output(), "busybox:1.28.4-glibc") { + t.Errorf("expected busybox:1.28.4-glibc to be loaded by docker inside minikube node. but got %s", rr.Output()) + } + + }) + }) } // validateConfigCmd asserts basic "config" command functionality