From dd6ab66e196879aece80354f7eafc0afb35841c0 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 26 May 2020 22:47:13 -0700 Subject: [PATCH] fix --- test/integration/functional_test.go | 26 ++++--------------------- test/integration/helpers.go | 30 ++++++++++++++++++----------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index f0ce08ec92..d8dccd7aab 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -161,7 +161,7 @@ func validateDockerEnv(ctx context.Context, t *testing.T, profile string) { var err error if runtime.GOOS == "windows" { // golang exec powershell needs some tricks ! c := exec.CommandContext(mctx, Target()+" -p "+profile+" docker-env | Invoke-Expression ;"+Target()+" status -p "+profile) - rr, err = Run(t, c) // golang exec powershell needs some tricks ! + rr, err = Run(t, c, true) // golang exec powershell needs some tricks ! } else { c := exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && "+Target()+" status -p "+profile) // we should be able to get minikube status with a bash which evaled docker-env @@ -855,18 +855,7 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) { t.Skipf("skipping: ssh unsupported by none") } want := "/home/docker\n" - var rr *RunResult - var err error - - if runtime.GOOS == "windows" { // golang exec powershell needs some tricks ! - cmd := exec.CommandContext(ctx, Target()+" -p "+profile+" ssh "+"pwd") - t.Logf("about to run %s: ", cmd.Args) - rr, err = Run(t, cmd) - t.Logf("rr is %+v: \n", rr) - t.Logf("err is %v: \n", err) - } else { - rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "pwd")) - } + rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "pwd")) if ctx.Err() == context.DeadlineExceeded { t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command()) } @@ -874,21 +863,14 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) { if err != nil { t.Errorf("failed to run an ssh command. args %q : %v", rr.Command(), err) } + if rr.Stdout.String() != want { t.Errorf("expected minikube ssh command output to be -%q- but got *%q*. args %q", want, rr.Stdout.String(), rr.Command()) } want = profile + "\n" - if runtime.GOOS == "windows" { // golang exec powershell needs some tricks ! - cmd := exec.CommandContext(ctx, Target()+" -p "+profile+" ssh "+"\"cat /etc/hostname\"") - t.Logf("about to run %s: ", cmd.Args) - rr, err = Run(t, cmd) - t.Logf("rr is %+v: \n", rr) - t.Logf("err is %v: \n", err) - } else { - rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat /etc/hostname")) - } + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "cat /etc/hostname")) if ctx.Err() == context.DeadlineExceeded { t.Errorf("failed to run command by deadline. exceeded timeout : %s", rr.Command()) } diff --git a/test/integration/helpers.go b/test/integration/helpers.go index f4e112a151..ff26494800 100644 --- a/test/integration/helpers.go +++ b/test/integration/helpers.go @@ -29,7 +29,6 @@ import ( "fmt" "io/ioutil" "os/exec" - "runtime" "strings" "testing" "time" @@ -88,16 +87,20 @@ func (rr RunResult) Output() string { } // Run is a test helper to log a command being executed \_(ツ)_/¯ -func Run(t *testing.T, cmd *exec.Cmd) (*RunResult, error) { +func Run(t *testing.T, cmd *exec.Cmd, powershell ...bool) (*RunResult, error) { t.Helper() + runInPowershell := false + if len(powershell) > 0 { + runInPowershell = powershell[0] + } var newCmd *exec.Cmd - if runtime.GOOS == "windows" { + if runInPowershell { psBin, err := exec.LookPath("powershell.exe") if err != nil { return &RunResult{}, errors.Wrapf(err, "lookup powershell") } - args := append([]string{"-NoProfile", "-NonInteractive"}, cmd.Args...) + args := append([]string{"-NoProfile"}, cmd.Args...) newCmd = exec.Command(psBin, args...) newCmd.Stdout = cmd.Stdout newCmd.Stderr = cmd.Stderr @@ -118,9 +121,10 @@ func Run(t *testing.T, cmd *exec.Cmd) (*RunResult, error) { elapsed := time.Since(start) if err == nil { // Reduce log spam - if elapsed > (1 * time.Second) { - t.Logf("(dbg) Done: %v: (%s)", rr.Command(), elapsed) - } + // TODO:medygh bring this back + // if elapsed > (1 * time.Second) { + t.Logf("(dbg) Done: %v: (%s)", rr.Command(), elapsed) + // } } else { if exitError, ok := err.(*exec.ExitError); ok { rr.ExitCode = exitError.ExitCode() @@ -138,17 +142,21 @@ type StartSession struct { } // Start starts a process in the background, streaming output -func Start(t *testing.T, cmd *exec.Cmd) (*StartSession, error) { +func Start(t *testing.T, cmd *exec.Cmd, powershell ...bool) (*StartSession, error) { t.Helper() - t.Logf("(dbg) daemon: %v", cmd.Args) + runInPowershell := false + if len(powershell) > 0 { + runInPowershell = powershell[0] + } + t.Logf("(dbg) daemon: %v", cmd.Args) var newCmd *exec.Cmd - if runtime.GOOS == "windows" { + if runInPowershell { psBin, err := exec.LookPath("powershell.exe") if err != nil { return &StartSession{}, errors.Wrapf(err, "lookup powershell") } - args := append([]string{"-NoProfile", "-NonInteractive"}, cmd.Args...) + args := append([]string{"-NoProfile"}, cmd.Args...) newCmd = exec.Command(psBin, args...) newCmd.Stdout = cmd.Stdout newCmd.Stderr = cmd.Stderr