Skip to content

Commit

Permalink
make tests pass again for non-Linux systems
Browse files Browse the repository at this point in the history
  • Loading branch information
Git-Jiro committed Oct 4, 2020
1 parent 5fd7f48 commit 190d0a3
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions pkg/minikube/command/exec_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os/exec"
"path"
"path/filepath"
"runtime"
"strconv"
"time"

Expand Down Expand Up @@ -90,8 +91,15 @@ func (e *execRunner) Copy(f assets.CopyableFile) error {
dst := path.Join(f.GetTargetDir(), f.GetTargetName())
if _, err := os.Stat(dst); err == nil {
glog.Infof("found %s, removing ...", dst)
if _, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst)); err != nil {
return errors.Wrapf(err, "error removing file %s", dst)
switch runtime.GOOS {
case "linux":
if _, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst)); err != nil {
return errors.Wrapf(err, "error removing file %s", dst)
}
default:
if err := os.Remove(dst); err != nil {
return errors.Wrapf(err, "error removing file %s", dst)
}
}
}

Expand All @@ -106,27 +114,38 @@ func (e *execRunner) Copy(f assets.CopyableFile) error {
return errors.Wrapf(err, "error converting permissions %s to integer", f.GetPermissions())
}

// write to TMP location ...
tmpfile, err := ioutil.TempFile("", "minikube")
if err != nil {
return errors.Wrapf(err, "error creating tempfile")
}
defer os.Remove(tmpfile.Name())
err = writeFile(tmpfile.Name(), f, os.FileMode(perms))
if err != nil {
return errors.Wrapf(err, "error writing to tempfile %s", tmpfile.Name())
switch runtime.GOOS {
case "linux":
// write to TMP location ...
tmpfile, err := ioutil.TempFile("", "minikube")
if err != nil {
return errors.Wrapf(err, "error creating tempfile")
}
defer os.Remove(tmpfile.Name())
err = writeFile(tmpfile.Name(), f, os.FileMode(perms))
if err != nil {
return errors.Wrapf(err, "error writing to tempfile %s", tmpfile.Name())
}
// ... then use SUDO to move to target
// then sudo cp -a src dst
_, err = e.RunCmd(exec.Command("sudo", "cp", "-a", tmpfile.Name(), dst))
return err

default:
return writeFile(dst, f, os.FileMode(perms))
}
// ... then use SUDO to move to target
// then sudo cp -a src dst
_, err = e.RunCmd(exec.Command("sudo", "cp", "-a", tmpfile.Name(), dst))

return err
}

// Remove removes a file
func (e *execRunner) Remove(f assets.CopyableFile) error {
dst := filepath.Join(f.GetTargetDir(), f.GetTargetName())
glog.Infof("rm: %s", dst)
_, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst))
return err
switch runtime.GOOS {
case "linux":
_, err := e.RunCmd(exec.Command("sudo", "rm", "-f", dst))
return err
default:
return os.Remove(dst)
}
}

0 comments on commit 190d0a3

Please sign in to comment.