Ensure we have a clear error message in case of wrong setup (previously it would just exit with no error message)

This commit is contained in:
Guillaume Tardif 2020-05-26 22:59:52 +02:00
parent d876f9e779
commit 66a83410dd
2 changed files with 16 additions and 0 deletions

View File

@ -192,8 +192,10 @@ func execMoby(ctx context.Context) {
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
fmt.Fprintln(os.Stderr, exiterr.Error())
os.Exit(exiterr.ExitCode())
}
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Exit(0)

View File

@ -31,6 +31,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
@ -65,6 +66,19 @@ func (s *E2eSuite) TestContextDefault() {
})
}
func (s *E2eSuite) TestSetupError() {
It("should display an error if cannot shell out to docker-classic", func() {
err := os.Setenv("PATH", s.BinDir)
Expect(err).To(BeNil())
err = os.Remove(filepath.Join(s.BinDir, "docker-classic"))
Expect(err).To(BeNil())
output, err := s.NewDockerCommand("ps").Exec()
Expect(output).To(ContainSubstring("docker-classic"))
Expect(output).To(ContainSubstring("not found"))
Expect(err).NotTo(BeNil())
})
}
func (s *E2eSuite) TestLegacy() {
It("should list all legacy commands", func() {
output := s.NewDockerCommand("--help").ExecOrDie()