11package main
22
33import (
4- "fmt"
54 "os/exec"
65 "strings"
76 "testing"
@@ -10,23 +9,29 @@ import (
109func TestCommitAfterContainerIsDone (t * testing.T ) {
1110 runCmd := exec .Command (dockerBinary , "run" , "-i" , "-a" , "stdin" , "busybox" , "echo" , "foo" )
1211 out , _ , _ , err := runCommandWithStdoutStderr (runCmd )
13- errorOut (err , t , fmt .Sprintf ("failed to run container: %v %v" , out , err ))
12+ if err != nil {
13+ t .Fatalf ("failed to run container: %s, %v" , out , err )
14+ }
1415
1516 cleanedContainerID := stripTrailingCharacters (out )
1617
1718 waitCmd := exec .Command (dockerBinary , "wait" , cleanedContainerID )
18- _ , _ , err = runCommandWithOutput (waitCmd )
19- errorOut (err , t , fmt .Sprintf ("error thrown while waiting for container: %s" , out ))
19+ if _ , _ , err = runCommandWithOutput (waitCmd ); err != nil {
20+ t .Fatalf ("error thrown while waiting for container: %s, %v" , out , err )
21+ }
2022
2123 commitCmd := exec .Command (dockerBinary , "commit" , cleanedContainerID )
2224 out , _ , err = runCommandWithOutput (commitCmd )
23- errorOut (err , t , fmt .Sprintf ("failed to commit container to image: %v %v" , out , err ))
25+ if err != nil {
26+ t .Fatalf ("failed to commit container to image: %s, %v" , out , err )
27+ }
2428
2529 cleanedImageID := stripTrailingCharacters (out )
2630
2731 inspectCmd := exec .Command (dockerBinary , "inspect" , cleanedImageID )
28- out , _ , err = runCommandWithOutput (inspectCmd )
29- errorOut (err , t , fmt .Sprintf ("failed to inspect image: %v %v" , out , err ))
32+ if out , _ , err = runCommandWithOutput (inspectCmd ); err != nil {
33+ t .Fatalf ("failed to inspect image: %s, %v" , out , err )
34+ }
3035
3136 deleteContainer (cleanedContainerID )
3237 deleteImages (cleanedImageID )
@@ -37,23 +42,29 @@ func TestCommitAfterContainerIsDone(t *testing.T) {
3742func TestCommitWithoutPause (t * testing.T ) {
3843 runCmd := exec .Command (dockerBinary , "run" , "-i" , "-a" , "stdin" , "busybox" , "echo" , "foo" )
3944 out , _ , _ , err := runCommandWithStdoutStderr (runCmd )
40- errorOut (err , t , fmt .Sprintf ("failed to run container: %v %v" , out , err ))
45+ if err != nil {
46+ t .Fatalf ("failed to run container: %s, %v" , out , err )
47+ }
4148
4249 cleanedContainerID := stripTrailingCharacters (out )
4350
4451 waitCmd := exec .Command (dockerBinary , "wait" , cleanedContainerID )
45- _ , _ , err = runCommandWithOutput (waitCmd )
46- errorOut (err , t , fmt .Sprintf ("error thrown while waiting for container: %s" , out ))
52+ if _ , _ , err = runCommandWithOutput (waitCmd ); err != nil {
53+ t .Fatalf ("error thrown while waiting for container: %s, %v" , out , err )
54+ }
4755
4856 commitCmd := exec .Command (dockerBinary , "commit" , "-p=false" , cleanedContainerID )
4957 out , _ , err = runCommandWithOutput (commitCmd )
50- errorOut (err , t , fmt .Sprintf ("failed to commit container to image: %v %v" , out , err ))
58+ if err != nil {
59+ t .Fatalf ("failed to commit container to image: %s, %v" , out , err )
60+ }
5161
5262 cleanedImageID := stripTrailingCharacters (out )
5363
5464 inspectCmd := exec .Command (dockerBinary , "inspect" , cleanedImageID )
55- out , _ , err = runCommandWithOutput (inspectCmd )
56- errorOut (err , t , fmt .Sprintf ("failed to inspect image: %v %v" , out , err ))
65+ if out , _ , err = runCommandWithOutput (inspectCmd ); err != nil {
66+ t .Fatalf ("failed to inspect image: %s, %v" , out , err )
67+ }
5768
5869 deleteContainer (cleanedContainerID )
5970 deleteImages (cleanedImageID )
@@ -81,7 +92,7 @@ func TestCommitNewFile(t *testing.T) {
8192 t .Fatal (err , out )
8293 }
8394 if actual := strings .Trim (out , "\r \n " ); actual != "koye" {
84- t .Fatalf ("expected output koye received %s " , actual )
95+ t .Fatalf ("expected output koye received %q " , actual )
8596 }
8697
8798 deleteAllContainers ()
@@ -92,7 +103,6 @@ func TestCommitNewFile(t *testing.T) {
92103
93104func TestCommitTTY (t * testing.T ) {
94105 cmd := exec .Command (dockerBinary , "run" , "-t" , "--name" , "tty" , "busybox" , "/bin/ls" )
95-
96106 if _ , err := runCommand (cmd ); err != nil {
97107 t .Fatal (err )
98108 }
@@ -105,7 +115,6 @@ func TestCommitTTY(t *testing.T) {
105115 imageID = strings .Trim (imageID , "\r \n " )
106116
107117 cmd = exec .Command (dockerBinary , "run" , "ttytest" , "/bin/ls" )
108-
109118 if _ , err := runCommand (cmd ); err != nil {
110119 t .Fatal (err )
111120 }
@@ -124,6 +133,7 @@ func TestCommitWithHostBindMount(t *testing.T) {
124133 if err != nil {
125134 t .Fatal (imageID , err )
126135 }
136+
127137 imageID = strings .Trim (imageID , "\r \n " )
128138
129139 cmd = exec .Command (dockerBinary , "run" , "bindtest" , "true" )
0 commit comments