1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #21477 from cpuguy83/better_logging_on_integration

Better logging for errors in some tests
This commit is contained in:
Alexander Morozov 2016-03-25 09:16:18 -07:00
commit d7b341bc06
5 changed files with 21 additions and 12 deletions

View file

@ -104,7 +104,11 @@ func (s *DockerSuite) TestEventsLimit(c *check.C) {
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
errChan <- exec.Command(dockerBinary, args...).Run()
out, err := exec.Command(dockerBinary, args...).CombinedOutput()
if err != nil {
err = fmt.Errorf("%v: %s", err, string(out))
}
errChan <- err
}()
}

View file

@ -76,12 +76,8 @@ func (s *DockerSuite) TestRunExitCodeZero(c *check.C) {
// the exit code should be 1
func (s *DockerSuite) TestRunExitCodeOne(c *check.C) {
_, exitCode, err := dockerCmdWithError("run", "busybox", "false")
if err != nil && !strings.Contains("exit status 1", fmt.Sprintf("%s", err)) {
c.Fatal(err)
}
if exitCode != 1 {
c.Errorf("container should've exited with exit code 1. Got %d", exitCode)
}
c.Assert(err, checker.NotNil)
c.Assert(exitCode, checker.Equals, 1)
}
// it should be possible to pipe in data via stdin to a process running in a container
@ -3907,6 +3903,9 @@ func (s *DockerSuite) TestRunStdinBlockedAfterContainerExit(c *check.C) {
in, err := cmd.StdinPipe()
c.Assert(err, check.IsNil)
defer in.Close()
stdout := bytes.NewBuffer(nil)
cmd.Stdout = stdout
cmd.Stderr = stdout
c.Assert(cmd.Start(), check.IsNil)
waitChan := make(chan error)
@ -3916,7 +3915,7 @@ func (s *DockerSuite) TestRunStdinBlockedAfterContainerExit(c *check.C) {
select {
case err := <-waitChan:
c.Assert(err, check.IsNil)
c.Assert(err, check.IsNil, check.Commentf(stdout.String()))
case <-time.After(30 * time.Second):
c.Fatal("timeout waiting for command to exit")
}

View file

@ -24,8 +24,8 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
go func() {
// Attempt to start attached to the container that won't start
// This should return an error immediately since the container can't be started
if _, _, err := dockerCmdWithError("start", "-a", "test2"); err == nil {
ch <- fmt.Errorf("Expected error but got none")
if out, _, err := dockerCmdWithError("start", "-a", "test2"); err == nil {
ch <- fmt.Errorf("Expected error but got none:\n%s", out)
}
close(ch)
}()

View file

@ -35,10 +35,12 @@ func (s *DockerSuite) TestWaitBlockedExitZero(c *check.C) {
chWait := make(chan string)
go func() {
chWait <- ""
out, _, _ := runCommandWithOutput(exec.Command(dockerBinary, "wait", containerID))
chWait <- out
}()
<-chWait // make sure the goroutine is started
time.Sleep(100 * time.Millisecond)
dockerCmd(c, "stop", containerID)
@ -84,7 +86,7 @@ func (s *DockerSuite) TestWaitBlockedExitRandom(c *check.C) {
select {
case err := <-chWait:
c.Assert(err, checker.IsNil)
c.Assert(err, checker.IsNil, check.Commentf(waitCmdOut.String()))
status, err := waitCmdOut.ReadString('\n')
c.Assert(err, checker.IsNil)
c.Assert(strings.TrimSpace(status), checker.Equals, "99", check.Commentf("expected exit 99, got %s", status))

View file

@ -468,7 +468,11 @@ func dockerCmdWithError(args ...string) (string, int, error) {
if err := validateArgs(args...); err != nil {
return "", 0, err
}
return integration.DockerCmdWithError(dockerBinary, args...)
out, code, err := integration.DockerCmdWithError(dockerBinary, args...)
if err != nil {
err = fmt.Errorf("%v: %s", err, out)
}
return out, code, err
}
func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int) {