From f9cc71a3e57e8a0eb0ba1a2b690e06d9ff4ac277 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Sat, 22 Aug 2020 09:20:59 -0700 Subject: [PATCH 1/2] Update TestSkaffold to use unique profile names, more debuggable --- test/integration/skaffold_test.go | 48 +++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/test/integration/skaffold_test.go b/test/integration/skaffold_test.go index ad02ecaac9ce..c37006e848c4 100644 --- a/test/integration/skaffold_test.go +++ b/test/integration/skaffold_test.go @@ -29,8 +29,8 @@ import ( "testing" "time" - "github.com/docker/machine/libmachine/mcnutils" "github.com/hashicorp/go-getter" + "github.com/otiai10/copy" "k8s.io/minikube/pkg/util/retry" ) @@ -38,9 +38,8 @@ func TestSkaffold(t *testing.T) { if NoneDriver() { t.Skip("none driver doesn't support `minikube docker-env`; skaffold depends on this command") } - // can't use a unique profile, as skaffold only recognizes the - // profile name 'minikube' as a local cluster - profile := "minikube" + + profile := UniqueProfileName("skaffold") ctx, cancel := context.WithTimeout(context.Background(), Minutes(5)) defer CleanupWithLogs(t, profile, cancel) @@ -51,32 +50,51 @@ func TestSkaffold(t *testing.T) { } defer os.Remove(tf.Name()) - // start minikube cluster - args := append([]string{"start", "-p", profile, "--memory=2200"}, StartArgs()...) - rr, err := Run(t, exec.CommandContext(ctx, Target(), args...)) + rr, err := Run(t, exec.CommandContext(ctx, tf.Name(), "version")) + if err != nil { + t.Fatalf("error running skaffold version: %v\n%s", err, rr.Output()) + } + t.Logf("skaffold version: %s", rr.Stdout.Bytes()) + + args := append([]string{"start", "-p", profile, "--memory=2600"}, StartArgs()...) + rr, err = Run(t, exec.CommandContext(ctx, Target(), args...)) if err != nil { t.Fatalf("starting minikube: %v\n%s", err, rr.Output()) } // make sure minikube binary is in path so that skaffold can access it abs, err := filepath.Abs(Target()) - // copy minikube binary to minikube - if err := mcnutils.CopyFile(Target(), filepath.Join(filepath.Dir(abs), "minikube")); err != nil { - t.Fatalf("error copying to minikube") - } if err != nil { - t.Fatalf("absolute path to minikube binary: %v", err) + t.Fatalf("unable to determine abs path: %v", err) } + + oldPath := os.Getenv("PATH") os.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(abs), os.Getenv("PATH"))) + defer func() { + os.Setenv("PATH", oldPath) + t.Logf("PATH is now %s", os.Getenv("PATH")) + }() + + t.Logf("PATH is now %s", os.Getenv("PATH")) + + if filepath.Base(Target()) != "minikube" { + new := filepath.Join(filepath.Dir(abs), "minikube") + t.Logf("copying %s to %s", Target(), new) + if err := copy.Copy(Target(), new); err != nil { + t.Fatalf("error copying to minikube") + } + } + // make sure 'docker' and 'minikube' are on PATH for _, binary := range []string{"minikube", "docker"} { - rr, err := Run(t, exec.CommandContext(ctx, "which", binary)) + _, err := exec.LookPath(binary) if err != nil { - t.Fatalf("'which %v' failed: check if %v is on PATH\n%v", binary, binary, rr.Output()) + t.Fatalf("%q is not in path", binary) } } + // make sure "skaffold run" exits without failure - cmd := exec.CommandContext(ctx, tf.Name(), "run", "--kube-context", profile, "--status-check=true", "--port-forward=false") + cmd := exec.CommandContext(ctx, tf.Name(), "run", "--minikube-profile", profile, "--kube-context", profile, "--status-check=true", "--port-forward=false") cmd.Dir = "testdata/skaffold" rr, err = Run(t, cmd) if err != nil { From e137ed2e0edd6fde38d8ee0ce082fad020cf960f Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Mon, 24 Aug 2020 11:10:07 -0700 Subject: [PATCH 2/2] Move PATH setting to occur closer to the exec call --- test/integration/skaffold_test.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/test/integration/skaffold_test.go b/test/integration/skaffold_test.go index c37006e848c4..ee22609ce6fb 100644 --- a/test/integration/skaffold_test.go +++ b/test/integration/skaffold_test.go @@ -68,15 +68,6 @@ func TestSkaffold(t *testing.T) { t.Fatalf("unable to determine abs path: %v", err) } - oldPath := os.Getenv("PATH") - os.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(abs), os.Getenv("PATH"))) - defer func() { - os.Setenv("PATH", oldPath) - t.Logf("PATH is now %s", os.Getenv("PATH")) - }() - - t.Logf("PATH is now %s", os.Getenv("PATH")) - if filepath.Base(Target()) != "minikube" { new := filepath.Join(filepath.Dir(abs), "minikube") t.Logf("copying %s to %s", Target(), new) @@ -93,6 +84,12 @@ func TestSkaffold(t *testing.T) { } } + oldPath := os.Getenv("PATH") + os.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(abs), os.Getenv("PATH"))) + defer func() { + os.Setenv("PATH", oldPath) + }() + // make sure "skaffold run" exits without failure cmd := exec.CommandContext(ctx, tf.Name(), "run", "--minikube-profile", profile, "--kube-context", profile, "--status-check=true", "--port-forward=false") cmd.Dir = "testdata/skaffold"