55 "strings"
66 "time"
77
8+ "github.com/docker/docker/pkg/integration/checker"
89 "github.com/go-check/check"
910)
1011
@@ -15,9 +16,9 @@ func (s *DockerSuite) TestStartAttachReturnsOnError(c *check.C) {
1516 dockerCmd (c , "wait" , "test" )
1617
1718 // Expect this to fail because the above container is stopped, this is what we want
18- if _ , _ , err := dockerCmdWithError ("run" , "-d" , "--name" , "test2" , "--link" , "test:test" , "busybox" ); err == nil {
19- c . Fatal ( "Expected error but got none" )
20- }
19+ out , _ , err := dockerCmdWithError ("run" , "-d" , "--name" , "test2" , "--link" , "test:test" , "busybox" )
20+ // err shouldn't be nil because container test2 try to link to stopped container
21+ c . Assert ( err , checker . NotNil , check . Commentf ( "out: %s" , out ))
2122
2223 ch := make (chan error )
2324 go func () {
@@ -47,12 +48,10 @@ func (s *DockerSuite) TestStartAttachCorrectExitCode(c *check.C) {
4748 dockerCmd (c , "wait" , out )
4849
4950 startOut , exitCode , err := dockerCmdWithError ("start" , "-a" , out )
50- if err != nil && ! strings .Contains ("exit status 1" , fmt .Sprintf ("%s" , err )) {
51- c .Fatalf ("start command failed unexpectedly with error: %v, output: %q" , err , startOut )
52- }
53- if exitCode != 1 {
54- c .Fatalf ("start -a did not respond with proper exit code: expected 1, got %d" , exitCode )
55- }
51+ // start command should fail
52+ c .Assert (err , checker .NotNil , check .Commentf ("startOut: %s" , startOut ))
53+ // start -a did not respond with proper exit code
54+ c .Assert (exitCode , checker .Equals , 1 , check .Commentf ("startOut: %s" , startOut ))
5655
5756}
5857
@@ -65,42 +64,35 @@ func (s *DockerSuite) TestStartAttachSilent(c *check.C) {
6564 dockerCmd (c , "wait" , name )
6665
6766 startOut , _ := dockerCmd (c , "start" , "-a" , name )
68- if expected := "test\n " ; startOut != expected {
69- c .Fatalf ("start -a produced unexpected output: expected %q, got %q" , expected , startOut )
70- }
67+ // start -a produced unexpected output
68+ c .Assert (startOut , checker .Equals , "test\n " )
7169}
7270
7371func (s * DockerSuite ) TestStartRecordError (c * check.C ) {
7472 testRequires (c , DaemonIsLinux )
7573 // when container runs successfully, we should not have state.Error
7674 dockerCmd (c , "run" , "-d" , "-p" , "9999:9999" , "--name" , "test" , "busybox" , "top" )
7775 stateErr , err := inspectField ("test" , "State.Error" )
78- c .Assert (err , check .IsNil )
79- if stateErr != "" {
80- c .Fatalf ("Expected to not have state error but got state.Error(%q)" , stateErr )
81- }
76+ c .Assert (err , checker .IsNil , check .Commentf ("stateErr: %s" , stateErr ))
77+ // Expected to not have state error
78+ c .Assert (stateErr , checker .Equals , "" )
8279
8380 // Expect this to fail and records error because of ports conflict
8481 out , _ , err := dockerCmdWithError ("run" , "-d" , "--name" , "test2" , "-p" , "9999:9999" , "busybox" , "top" )
85- if err == nil {
86- c .Fatalf ("Expected error but got none, output %q" , out )
87- }
82+ // err shouldn't be nil because docker run will fail
83+ c .Assert (err , checker .NotNil , check .Commentf ("out: %s" , out ))
8884
8985 stateErr , err = inspectField ("test2" , "State.Error" )
90- c .Assert (err , check .IsNil )
91- expected := "port is already allocated"
92- if stateErr == "" || ! strings .Contains (stateErr , expected ) {
93- c .Fatalf ("State.Error(%q) does not include %q" , stateErr , expected )
94- }
86+ c .Assert (err , check .IsNil , check .Commentf ("stateErr: %s" , stateErr ))
87+ c .Assert (stateErr , checker .Contains , "port is already allocated" )
9588
9689 // Expect the conflict to be resolved when we stop the initial container
9790 dockerCmd (c , "stop" , "test" )
9891 dockerCmd (c , "start" , "test2" )
9992 stateErr , err = inspectField ("test2" , "State.Error" )
100- c .Assert (err , check .IsNil )
101- if stateErr != "" {
102- c .Fatalf ("Expected to not have state error but got state.Error(%q)" , stateErr )
103- }
93+ c .Assert (err , check .IsNil , check .Commentf ("stateErr: %s" , stateErr ))
94+ // Expected to not have state error but got one
95+ c .Assert (stateErr , checker .Equals , "" )
10496}
10597
10698func (s * DockerSuite ) TestStartPausedContainer (c * check.C ) {
@@ -111,9 +103,11 @@ func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
111103
112104 dockerCmd (c , "pause" , "testing" )
113105
114- if out , _ , err := dockerCmdWithError ("start" , "testing" ); err == nil || ! strings .Contains (out , "Cannot start a paused container, try unpause instead." ) {
115- c .Fatalf ("an error should have been shown that you cannot start paused container: %s\n %v" , out , err )
116- }
106+ out , _ , err := dockerCmdWithError ("start" , "testing" )
107+ // an error should have been shown that you cannot start paused container
108+ c .Assert (err , checker .NotNil , check .Commentf ("out: %s" , out ))
109+ // an error should have been shown that you cannot start paused container
110+ c .Assert (out , checker .Contains , "Cannot start a paused container, try unpause instead." )
117111}
118112
119113func (s * DockerSuite ) TestStartMultipleContainers (c * check.C ) {
@@ -129,25 +123,24 @@ func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {
129123 dockerCmd (c , "stop" , "parent" )
130124
131125 out , err := inspectField ("parent" , "State.Running" )
132- c .Assert (err , check .IsNil )
133- if out != "false" {
134- c .Fatal ("Container should be stopped" )
135- }
126+ c .Assert (err , check .IsNil , check .Commentf ("out: %s" , out ))
127+ // Container should be stopped
128+ c .Assert (out , checker .Equals , "false" )
136129
137130 // start all the three containers, container `child_first` start first which should be failed
138131 // container 'parent' start second and then start container 'child_second'
139132 out , _ , err = dockerCmdWithError ("start" , "child_first" , "parent" , "child_second" )
140- if ! strings .Contains (out , "Cannot start container child_first" ) || err == nil {
141- c .Fatal ("Expected error but got none" )
142- }
133+ // err shouldn't be nil because start will fail
134+ c .Assert (err , checker .NotNil , check .Commentf ("out: %s" , out ))
135+ // output does not correspond to what was expected
136+ c .Assert (out , checker .Contains , "Cannot start container child_first" )
143137
144138 for container , expected := range map [string ]string {"parent" : "true" , "child_first" : "false" , "child_second" : "true" } {
145139 out , err := inspectField (container , "State.Running" )
146- c .Assert (err , check .IsNil )
147- if out != expected {
148- c .Fatal ("Container running state wrong" )
149- }
150-
140+ // Container running state wrong
141+ c .Assert (err , check .IsNil , check .Commentf ("out: %s" , out ))
142+ // Container running state wrong
143+ c .Assert (out , checker .Equals , expected )
151144 }
152145}
153146
@@ -166,19 +159,18 @@ func (s *DockerSuite) TestStartAttachMultipleContainers(c *check.C) {
166159 // test start and attach multiple containers at once, expected error
167160 for _ , option := range []string {"-a" , "-i" , "-ai" } {
168161 out , _ , err := dockerCmdWithError ("start" , option , "test1" , "test2" , "test3" )
169- if ! strings .Contains (out , "You cannot start and attach multiple containers at once." ) || err == nil {
170- c .Fatal ("Expected error but got none" )
171- }
162+ // err shouldn't be nil because start will fail
163+ c .Assert (err , checker .NotNil , check .Commentf ("out: %s" , out ))
164+ // output does not correspond to what was expected
165+ c .Assert (out , checker .Contains , "You cannot start and attach multiple containers at once." )
172166 }
173167
174168 // confirm the state of all the containers be stopped
175169 for container , expected := range map [string ]string {"test1" : "false" , "test2" : "false" , "test3" : "false" } {
176170 out , err := inspectField (container , "State.Running" )
177- if err != nil {
178- c .Fatal (out , err )
179- }
180- if out != expected {
181- c .Fatal ("Container running state wrong" )
182- }
171+ // Container running state wrong
172+ c .Assert (err , check .IsNil , check .Commentf ("out: %s" , out ))
173+ // Container running state wrong
174+ c .Assert (out , checker .Equals , expected )
183175 }
184176}
0 commit comments