mirror of
https://github.com/docker/compose.git
synced 2025-07-13 00:34:29 +02:00
Fix windows E2E suite setup to work properly on windows
This commit is contained in:
parent
c73998bd2d
commit
bed0b81343
@ -106,7 +106,7 @@ func (s *E2eSuite) TestSetupError() {
|
|||||||
It("should display an error if cannot shell out to docker-classic", func() {
|
It("should display an error if cannot shell out to docker-classic", func() {
|
||||||
err := os.Setenv("PATH", s.BinDir)
|
err := os.Setenv("PATH", s.BinDir)
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
err = os.Remove(filepath.Join(s.BinDir, "docker-classic"))
|
err = os.Remove(filepath.Join(s.BinDir, DockerClassicExecutable()))
|
||||||
Expect(err).To(BeNil())
|
Expect(err).To(BeNil())
|
||||||
output, err := s.NewDockerCommand("ps").Exec()
|
output, err := s.NewDockerCommand("ps").Exec()
|
||||||
Expect(output).To(ContainSubstring("docker-classic"))
|
Expect(output).To(ContainSubstring("docker-classic"))
|
||||||
|
@ -62,7 +62,7 @@ func (s *Suite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
s.T().Fail()
|
s.T().Fail()
|
||||||
})
|
})
|
||||||
s.linkClassicDocker()
|
s.copyExecutablesInBinDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TearDownSuite is run after all tests
|
// TearDownSuite is run after all tests
|
||||||
@ -79,22 +79,35 @@ func dirContents(dir string) []string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Suite) linkClassicDocker() {
|
func (s *Suite) copyExecutablesInBinDir() {
|
||||||
p, err := exec.LookPath("docker-classic")
|
p, err := exec.LookPath(DockerClassicExecutable())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p, err = exec.LookPath("docker")
|
p, err = exec.LookPath(dockerExecutable())
|
||||||
}
|
}
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
err = os.Symlink(p, filepath.Join(s.BinDir, "docker-classic"))
|
err = copyFiles(p, filepath.Join(s.BinDir, DockerClassicExecutable()))
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
dockerPath, err := filepath.Abs("../../bin/docker")
|
dockerPath, err := filepath.Abs("../../bin/" + dockerExecutable())
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
err = os.Symlink(dockerPath, filepath.Join(s.BinDir, "docker"))
|
err = copyFiles(dockerPath, filepath.Join(s.BinDir, dockerExecutable()))
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", s.BinDir, os.Getenv("PATH")))
|
err = os.Setenv("PATH", fmt.Sprintf("%s:%s", s.BinDir, os.Getenv("PATH")))
|
||||||
gomega.Expect(err).To(gomega.BeNil())
|
gomega.Expect(err).To(gomega.BeNil())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyFiles(sourceFile string, destinationFile string) error {
|
||||||
|
input, err := ioutil.ReadFile(sourceFile)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(destinationFile, input, 0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// BeforeTest is run before each test
|
// BeforeTest is run before each test
|
||||||
func (s *Suite) BeforeTest(suite, test string) {
|
func (s *Suite) BeforeTest(suite, test string) {
|
||||||
d, _ := ioutil.TempDir("", "")
|
d, _ := ioutil.TempDir("", "")
|
||||||
@ -109,12 +122,16 @@ func (s *Suite) AfterTest(suite, test string) {
|
|||||||
|
|
||||||
// ListProcessesCommand creates a command to list processes, "tasklist" on windows, "ps" otherwise.
|
// ListProcessesCommand creates a command to list processes, "tasklist" on windows, "ps" otherwise.
|
||||||
func (s *Suite) ListProcessesCommand() *CmdContext {
|
func (s *Suite) ListProcessesCommand() *CmdContext {
|
||||||
if runtime.GOOS == "windows" {
|
if isWindows() {
|
||||||
return s.NewCommand("tasklist")
|
return s.NewCommand("tasklist")
|
||||||
}
|
}
|
||||||
return s.NewCommand("ps")
|
return s.NewCommand("ps")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isWindows() bool {
|
||||||
|
return runtime.GOOS == "windows"
|
||||||
|
}
|
||||||
|
|
||||||
// NewCommand creates a command context.
|
// NewCommand creates a command context.
|
||||||
func (s *Suite) NewCommand(command string, args ...string) *CmdContext {
|
func (s *Suite) NewCommand(command string, args ...string) *CmdContext {
|
||||||
return &CmdContext{
|
return &CmdContext{
|
||||||
@ -125,12 +142,19 @@ func (s *Suite) NewCommand(command string, args ...string) *CmdContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dockerExecutable() string {
|
func dockerExecutable() string {
|
||||||
if runtime.GOOS == "windows" {
|
if isWindows() {
|
||||||
return "docker.exe"
|
return "docker.exe"
|
||||||
}
|
}
|
||||||
return "docker"
|
return "docker"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DockerClassicExecutable() string {
|
||||||
|
if isWindows() {
|
||||||
|
return "docker-classic.exe"
|
||||||
|
}
|
||||||
|
return "docker-classic"
|
||||||
|
}
|
||||||
|
|
||||||
// NewDockerCommand creates a docker builder.
|
// NewDockerCommand creates a docker builder.
|
||||||
func (s *Suite) NewDockerCommand(args ...string) *CmdContext {
|
func (s *Suite) NewDockerCommand(args ...string) *CmdContext {
|
||||||
return s.NewCommand(dockerExecutable(), args...)
|
return s.NewCommand(dockerExecutable(), args...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user