diff --git a/test/integration/fn_mount_cmd.go b/test/integration/fn_mount_cmd.go index 3fe7ae60d1b800b6b699febfbc43b295f73744cc..8fb9d1cc9c7fa44075670a050499cdc44a88a54d 100644 --- a/test/integration/fn_mount_cmd.go +++ b/test/integration/fn_mount_cmd.go @@ -70,11 +70,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { //nol args := []string{"mount", "-p", profile, fmt.Sprintf("%s:%s", tempDir, guestMount), "--alsologtostderr", "-v=1"} var ss *StartSession - if runtime.GOOS == "windows" { - ss, err = Start(t, exec.CommandContext(mctx, Target(), args...), true) - } else { - ss, err = Start(t, exec.CommandContext(mctx, Target(), args...)) - } + ss, err = Start(t, exec.CommandContext(mctx, Target(), args...)) if err != nil { t.Fatalf("%v failed: %v", args, err) } @@ -84,11 +80,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { //nol var err error if t.Failed() { t.Logf("%q failed, getting debug info...", t.Name()) - if runtime.GOOS == "windows" { - rr, err = Run(t, exec.Command(Target(), "-p", profile, "ssh", "mount | grep 9p; ls -la /mount-9p; cat /mount-9p/pod-dates"), true) - } else { - rr, err = Run(t, exec.Command(Target(), "-p", profile, "ssh", "mount | grep 9p; ls -la /mount-9p; cat /mount-9p/pod-dates")) - } + rr, err = Run(t, exec.Command(Target(), "-p", profile, "ssh", "mount | grep 9p; ls -la /mount-9p; cat /mount-9p/pod-dates")) if err != nil { t.Logf("debugging command %q failed : %v", rr.Command(), err) } else { @@ -97,11 +89,7 @@ func validateMountCmd(ctx context.Context, t *testing.T, profile string) { //nol } // Cleanup in advance of future tests - if runtime.GOOS == "windows" { - rr, err = Run(t, exec.Command(Target(), "-p", profile, "ssh", "sudo umount -f /mount-9p"), true) - } else { - rr, err = Run(t, exec.Command(Target(), "-p", profile, "ssh", "sudo umount -f /mount-9p")) - } + rr, err = Run(t, exec.Command(Target(), "-p", profile, "ssh", "sudo umount -f /mount-9p")) if err != nil { t.Logf("%q: %v", rr.Command(), err) } diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 9a6dddaf75ff60f3be5979c0d171d86d45159e7e..9705b95d6583dd98bfb85a94e082f2037dc1a84d 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, true) // golang exec powershell needs some tricks ! + rr, err = Run(t, c) // 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 @@ -182,7 +182,7 @@ func validateDockerEnv(ctx context.Context, t *testing.T, profile string) { // do a eval $(minikube -p profile docker-env) and check if we are point to docker inside minikube if runtime.GOOS == "windows" { // testing docker-env eval in powershell c := exec.CommandContext(mctx, Target(), "-p "+profile+" docker-env | Invoke-Expression ; docker images") - rr, err = Run(t, c, true) // golang exec powershell needs some tricks ! + rr, err = Run(t, c) // golang exec powershell needs some tricks ! } else { c := exec.CommandContext(mctx, "/bin/bash", "-c", "eval $("+Target()+" -p "+profile+" docker-env) && docker images") rr, err = Run(t, c) @@ -520,12 +520,7 @@ func validateCacheCmd(ctx context.Context, t *testing.T, profile string) { var rr *RunResult var err error - if runtime.GOOS == "windows" { - rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo crictl images"), true) - } else { - rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo", "crictl", "images")) - } - + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo", "crictl", "images")) if err != nil { t.Errorf("failed to get images by %q ssh %v", rr.Command(), err) } @@ -544,11 +539,7 @@ func validateCacheCmd(ctx context.Context, t *testing.T, profile string) { // deleting image inside minikube node manually var rr *RunResult var err error - if runtime.GOOS == "windows" { - rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo docker rmi "+img), true) // for some reason crictl rmi doesn't work - } else { - rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo", "docker", "rmi", img)) - } + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "ssh", "sudo", "docker", "rmi", img)) if err != nil { t.Errorf("failed to delete inside the node %q : %v", rr.Command(), err) @@ -864,7 +855,7 @@ func validateSSHCmd(ctx context.Context, t *testing.T, profile string) { 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, true) + rr, err = Run(t, cmd) t.Logf("rr is %+v: \n", rr) t.Logf("err is %v: \n", err) } else { diff --git a/test/integration/helpers.go b/test/integration/helpers.go index 9edce414514baaef2662d9aae3469c3aac1ce9cb..5940301f9f362a362d5bdfd262162c2eb90fde7c 100644 --- a/test/integration/helpers.go +++ b/test/integration/helpers.go @@ -29,11 +29,13 @@ import ( "fmt" "io/ioutil" "os/exec" + "runtime" "strings" "testing" "time" "github.com/docker/machine/libmachine/state" + "github.com/pkg/errors" "github.com/shirou/gopsutil/process" core "k8s.io/api/core/v1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -86,25 +88,22 @@ func (rr RunResult) Output() string { } // Run is a test helper to log a command being executed \_(ツ)_/¯ -func Run(t *testing.T, cmd *exec.Cmd, powershell ...bool) (*RunResult, error) { +func Run(t *testing.T, cmd *exec.Cmd) (*RunResult, error) { t.Helper() - isPowershell := false - if len(powershell) > 0 { - isPowershell = powershell[0] - } - newCmd := cmd - if isPowershell { + var newCmd *exec.Cmd + if runtime.GOOS == "windows" { psBin, err := exec.LookPath("powershell.exe") if err != nil { - return &RunResult{}, err + return &RunResult{}, errors.Wrapf(err, "lookup powershell") } args := append([]string{"-NoProfile", "-NonInteractive"}, cmd.Args...) newCmd = exec.Command(psBin, args...) - + } else { + newCmd = cmd } - rr := &RunResult{Args: newCmd.Args} + rr := &RunResult{Args: cmd.Args} t.Logf("(dbg) Run: %v", rr.Command()) @@ -136,30 +135,27 @@ type StartSession struct { } // Start starts a process in the background, streaming output -func Start(t *testing.T, cmd *exec.Cmd, powershell ...bool) (*StartSession, error) { +func Start(t *testing.T, cmd *exec.Cmd) (*StartSession, error) { t.Helper() t.Logf("(dbg) daemon: %v", cmd.Args) - isPowershell := false - if len(powershell) > 0 { - isPowershell = powershell[0] - } - - newCmd := cmd - if isPowershell { + var newCmd *exec.Cmd + if runtime.GOOS == "windows" { psBin, err := exec.LookPath("powershell.exe") if err != nil { - return nil, err + return &StartSession{}, errors.Wrapf(err, "lookup powershell") } args := append([]string{"-NoProfile", "-NonInteractive"}, cmd.Args...) newCmd = exec.Command(psBin, args...) + } else { + newCmd = cmd } stdoutPipe, err := newCmd.StdoutPipe() if err != nil { t.Fatalf("stdout pipe failed: %v %v", newCmd.Args, err) } - stderrPipe, err := cmd.StderrPipe() + stderrPipe, err := newCmd.StderrPipe() if err != nil { t.Fatalf("stderr pipe failed: %v %v", newCmd.Args, err) }