Changing e2e test PATH to make windows tests pass

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-09-17 13:58:20 +02:00
parent d320d5460c
commit 17bda79ca1
2 changed files with 12 additions and 7 deletions

View File

@ -295,7 +295,7 @@ func TestLegacy(t *testing.T) {
t.Run("run without HOME defined", func(t *testing.T) { t.Run("run without HOME defined", func(t *testing.T) {
cmd := c.NewDockerCmd("ps") cmd := c.NewDockerCmd("ps")
cmd.Env = []string{"PATH=" + c.BinDir} cmd.Env = []string{"PATH=" + c.PathEnvVar()}
res := icmd.RunCmd(cmd) res := icmd.RunCmd(cmd)
res.Assert(t, icmd.Expected{ res.Assert(t, icmd.Expected{
ExitCode: 0, ExitCode: 0,
@ -306,7 +306,7 @@ func TestLegacy(t *testing.T) {
t.Run("run without write access to context store", func(t *testing.T) { t.Run("run without write access to context store", func(t *testing.T) {
cmd := c.NewDockerCmd("ps") 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 := icmd.RunCmd(cmd)
res.Assert(t, icmd.Expected{ res.Assert(t, icmd.Expected{
ExitCode: 0, ExitCode: 0,

View File

@ -143,14 +143,10 @@ func CopyFile(sourceFile string, destinationFile string) error {
// NewCmd creates a cmd object configured with the test environment set // NewCmd creates a cmd object configured with the test environment set
func (c *E2eCLI) NewCmd(command string, args ...string) icmd.Cmd { 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(), env := append(os.Environ(),
"DOCKER_CONFIG="+c.ConfigDir, "DOCKER_CONFIG="+c.ConfigDir,
"KUBECONFIG=invalid", "KUBECONFIG=invalid",
"PATH="+path, "PATH="+c.PathEnvVar(),
) )
return icmd.Cmd{ return icmd.Cmd{
Command: append([]string{command}, args...), Command: append([]string{command}, args...),
@ -176,6 +172,15 @@ func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result {
return res 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 // GoldenFile golden file specific to platform
func GoldenFile(name string) string { func GoldenFile(name string) string {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {