diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 54e4c99dc..e2b368876 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -295,7 +295,7 @@ func TestLegacy(t *testing.T) { t.Run("run without HOME defined", func(t *testing.T) { cmd := c.NewDockerCmd("ps") - cmd.Env = []string{"PATH=" + c.BinDir} + cmd.Env = []string{"PATH=" + c.PathEnvVar()} res := icmd.RunCmd(cmd) res.Assert(t, icmd.Expected{ ExitCode: 0, @@ -306,7 +306,7 @@ func TestLegacy(t *testing.T) { t.Run("run without write access to context store", func(t *testing.T) { cmd := c.NewDockerCmd("ps") - cmd.Env = []string{"PATH=" + c.BinDir, "HOME=/doesnotexist/"} + cmd.Env = []string{"PATH=" + c.PathEnvVar(), "HOME=/doesnotexist/"} res := icmd.RunCmd(cmd) res.Assert(t, icmd.Expected{ ExitCode: 0, diff --git a/tests/framework/e2e.go b/tests/framework/e2e.go index a865fde88..80daa8737 100644 --- a/tests/framework/e2e.go +++ b/tests/framework/e2e.go @@ -143,14 +143,10 @@ func CopyFile(sourceFile string, destinationFile string) error { // NewCmd creates a cmd object configured with the test environment set func (c *E2eCLI) NewCmd(command string, args ...string) icmd.Cmd { - path := c.BinDir + ":" + os.Getenv("PATH") - if runtime.GOOS == "windows" { - path = c.BinDir + ";" + os.Getenv("PATH") - } env := append(os.Environ(), "DOCKER_CONFIG="+c.ConfigDir, "KUBECONFIG=invalid", - "PATH="+path, + "PATH="+c.PathEnvVar(), ) return icmd.Cmd{ Command: append([]string{command}, args...), @@ -176,6 +172,15 @@ func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result { return res } +// PathEnvVar returns path (os sensitive) for running test +func (c *E2eCLI) PathEnvVar() string { + path := c.BinDir + ":" + os.Getenv("PATH") + if runtime.GOOS == "windows" { + path = c.BinDir + ";" + os.Getenv("PATH") + } + return path +} + // GoldenFile golden file specific to platform func GoldenFile(name string) string { if runtime.GOOS == "windows" {