Browse Source

Better logging for errors in some tests

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 9 years ago
parent
commit
42df9edc4a

+ 5 - 1
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
 		}()
 	}
 

+ 6 - 7
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")
 	}

+ 2 - 2
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)
 	}()

+ 3 - 1
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))

+ 5 - 1
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) {