Browse code

integ-cli: better debug output for run & import

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/09/12 22:51:21
Showing 2 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 package main
2 2
 
3 3
 import (
4
-	"fmt"
5 4
 	"os/exec"
6 5
 	"strings"
7 6
 	"testing"
... ...
@@ -10,7 +9,9 @@ import (
10 10
 func TestImportDisplay(t *testing.T) {
11 11
 	importCmd := exec.Command(dockerBinary, "import", "https://github.com/ewindisch/docker-cirros/raw/master/cirros-0.3.0-x86_64-lxc.tar.gz")
12 12
 	out, _, err := runCommandWithOutput(importCmd)
13
-	errorOut(err, t, fmt.Sprintf("import failed with errors: %v", err))
13
+	if err != nil {
14
+		t.Errorf("import failed with errors: %v, output: %q", err, out)
15
+	}
14 16
 
15 17
 	if n := strings.Count(out, "\n"); n != 2 {
16 18
 		t.Fatalf("display is messed up: %d '\\n' instead of 2", n)
... ...
@@ -24,7 +24,9 @@ import (
24 24
 func TestDockerRunEchoStdout(t *testing.T) {
25 25
 	runCmd := exec.Command(dockerBinary, "run", "busybox", "echo", "test123")
26 26
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
27
-	errorOut(err, t, out)
27
+	if err != nil {
28
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
29
+	}
28 30
 
29 31
 	if out != "test123\n" {
30 32
 		t.Errorf("container should've printed 'test123'")
... ...
@@ -39,7 +41,9 @@ func TestDockerRunEchoStdout(t *testing.T) {
39 39
 func TestDockerRunEchoStdoutWithMemoryLimit(t *testing.T) {
40 40
 	runCmd := exec.Command(dockerBinary, "run", "-m", "2786432", "busybox", "echo", "test")
41 41
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
42
-	errorOut(err, t, out)
42
+	if err != nil {
43
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
44
+	}
43 45
 
44 46
 	out = strings.Trim(out, "\r\n")
45 47
 
... ...
@@ -57,7 +61,9 @@ func TestDockerRunEchoStdoutWithMemoryLimit(t *testing.T) {
57 57
 func TestDockerRunEchoStdoutWitCPULimit(t *testing.T) {
58 58
 	runCmd := exec.Command(dockerBinary, "run", "-c", "1000", "busybox", "echo", "test")
59 59
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
60
-	errorOut(err, t, out)
60
+	if err != nil {
61
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
62
+	}
61 63
 
62 64
 	if out != "test\n" {
63 65
 		t.Errorf("container should've printed 'test'")
... ...
@@ -72,7 +78,9 @@ func TestDockerRunEchoStdoutWitCPULimit(t *testing.T) {
72 72
 func TestDockerRunEchoStdoutWithCPUAndMemoryLimit(t *testing.T) {
73 73
 	runCmd := exec.Command(dockerBinary, "run", "-c", "1000", "-m", "2786432", "busybox", "echo", "test")
74 74
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
75
-	errorOut(err, t, out)
75
+	if err != nil {
76
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
77
+	}
76 78
 
77 79
 	if out != "test\n" {
78 80
 		t.Errorf("container should've printed 'test', got %q instead", out)
... ...
@@ -87,7 +95,9 @@ func TestDockerRunEchoStdoutWithCPUAndMemoryLimit(t *testing.T) {
87 87
 func TestDockerRunEchoNamedContainer(t *testing.T) {
88 88
 	runCmd := exec.Command(dockerBinary, "run", "--name", "testfoonamedcontainer", "busybox", "echo", "test")
89 89
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
90
-	errorOut(err, t, out)
90
+	if err != nil {
91
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
92
+	}
91 93
 
92 94
 	if out != "test\n" {
93 95
 		t.Errorf("container should've printed 'test'")
... ...
@@ -106,7 +116,9 @@ func TestDockerRunEchoNamedContainer(t *testing.T) {
106 106
 func TestDockerRunLeakyFileDescriptors(t *testing.T) {
107 107
 	runCmd := exec.Command(dockerBinary, "run", "busybox", "ls", "-C", "/proc/self/fd")
108 108
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
109
-	errorOut(err, t, out)
109
+	if err != nil {
110
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
111
+	}
110 112
 
111 113
 	// normally, we should only get 0, 1, and 2, but 3 gets created by "ls" when it does "opendir" on the "fd" directory
112 114
 	if out != "0  1  2  3\n" {
... ...
@@ -123,7 +135,9 @@ func TestDockerRunLeakyFileDescriptors(t *testing.T) {
123 123
 func TestDockerRunPingGoogle(t *testing.T) {
124 124
 	runCmd := exec.Command(dockerBinary, "run", "busybox", "ping", "-c", "1", "8.8.8.8")
125 125
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
126
-	errorOut(err, t, out)
126
+	if err != nil {
127
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
128
+	}
127 129
 
128 130
 	errorOut(err, t, "container should've been able to ping 8.8.8.8")
129 131
 
... ...
@@ -170,7 +184,9 @@ func TestDockerRunExitCodeOne(t *testing.T) {
170 170
 func TestRunStdinPipe(t *testing.T) {
171 171
 	runCmd := exec.Command("bash", "-c", `echo "blahblah" | docker run -i -a stdin busybox cat`)
172 172
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
173
-	errorOut(err, t, out)
173
+	if err != nil {
174
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
175
+	}
174 176
 
175 177
 	out = stripTrailingCharacters(out)
176 178
 
... ...
@@ -205,7 +221,9 @@ func TestRunStdinPipe(t *testing.T) {
205 205
 func TestDockerRunDetachedContainerIDPrinting(t *testing.T) {
206 206
 	runCmd := exec.Command(dockerBinary, "run", "-d", "busybox", "true")
207 207
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
208
-	errorOut(err, t, out)
208
+	if err != nil {
209
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
210
+	}
209 211
 
210 212
 	out = stripTrailingCharacters(out)
211 213
 
... ...
@@ -235,7 +253,9 @@ func TestDockerRunDetachedContainerIDPrinting(t *testing.T) {
235 235
 func TestDockerRunWorkingDirectory(t *testing.T) {
236 236
 	runCmd := exec.Command(dockerBinary, "run", "-w", "/root", "busybox", "pwd")
237 237
 	out, _, _, err := runCommandWithStdoutStderr(runCmd)
238
-	errorOut(err, t, out)
238
+	if err != nil {
239
+		t.Fatalf("failed to run container: %v, output: %q", err, out)
240
+	}
239 241
 
240 242
 	out = stripTrailingCharacters(out)
241 243