From 42df9edc4a6ccfff6869fd14b2128ca3312e99db Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Thu, 24 Mar 2016 12:43:04 -0400 Subject: [PATCH] Better logging for errors in some tests Signed-off-by: Brian Goff --- integration-cli/docker_cli_events_test.go | 6 +++++- integration-cli/docker_cli_run_test.go | 13 ++++++------- integration-cli/docker_cli_start_test.go | 4 ++-- integration-cli/docker_cli_wait_test.go | 4 +++- integration-cli/docker_utils.go | 6 +++++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/integration-cli/docker_cli_events_test.go b/integration-cli/docker_cli_events_test.go index f426650c2b..177879e8f7 100644 --- a/integration-cli/docker_cli_events_test.go +++ b/integration-cli/docker_cli_events_test.go @@ -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 }() } diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index b6bb6cae96..75bb34efab 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -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") } diff --git a/integration-cli/docker_cli_start_test.go b/integration-cli/docker_cli_start_test.go index 43342191c2..2c984fabe9 100644 --- a/integration-cli/docker_cli_start_test.go +++ b/integration-cli/docker_cli_start_test.go @@ -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) }() diff --git a/integration-cli/docker_cli_wait_test.go b/integration-cli/docker_cli_wait_test.go index 299339756f..961aef5525 100644 --- a/integration-cli/docker_cli_wait_test.go +++ b/integration-cli/docker_cli_wait_test.go @@ -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)) diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 63955970af..23313c9d3c 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -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) {