Jelajahi Sumber

Merge pull request #629 from docker/fix_windows_ci

Changing e2e test PATH to make windows tests pass
Guillaume Tardif 5 tahun lalu
induk
melakukan
e6925b4217
2 mengubah file dengan 12 tambahan dan 7 penghapusan
  1. 2 2
      tests/e2e/e2e_test.go
  2. 10 5
      tests/framework/e2e.go

+ 2 - 2
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,

+ 10 - 5
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" {