Skip to content

Commit

Permalink
Better logging for errors in some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Mar 25, 2016
1 parent 6ad9def commit 42df9ed
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
6 changes: 5 additions & 1 deletion integration-cli/docker_cli_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
}

Expand Down
13 changes: 6 additions & 7 deletions integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions integration-cli/docker_cli_start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}()
Expand Down
4 changes: 3 additions & 1 deletion integration-cli/docker_cli_wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion integration-cli/docker_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 42df9ed

Please sign in to comment.