@@ -52,29 +52,20 @@ func (s *DockerSuite) TestExecApiCreateNoValidContentType(c *check.C) {
5252func (s * DockerSuite ) TestExecAPIStart (c * check.C ) {
5353 dockerCmd (c , "run" , "-d" , "--name" , "test" , "busybox" , "top" )
5454
55- createExec := func () string {
56- _ , b , err := sockRequest ("POST" , fmt .Sprintf ("/containers/%s/exec" , "test" ), map [string ]interface {}{"Cmd" : []string {"true" }})
57- c .Assert (err , check .IsNil , check .Commentf (string (b )))
58-
59- createResp := struct {
60- ID string `json:"Id"`
61- }{}
62- c .Assert (json .Unmarshal (b , & createResp ), check .IsNil , check .Commentf (string (b )))
63- return createResp .ID
64- }
65-
6655 startExec := func (id string , code int ) {
6756 resp , body , err := sockRequestRaw ("POST" , fmt .Sprintf ("/exec/%s/start" , id ), strings .NewReader (`{"Detach": true}` ), "application/json" )
6857 c .Assert (err , check .IsNil )
6958
7059 b , err := readBody (body )
71- c .Assert (err , check .IsNil , check .Commentf (string (b )))
72- c .Assert (resp .StatusCode , check .Equals , code , check .Commentf (string (b )))
60+ comment := check .Commentf ("response body: %s" , b )
61+ c .Assert (err , check .IsNil , comment )
62+ c .Assert (resp .StatusCode , check .Equals , code , comment )
7363 }
7464
75- startExec (createExec (), http .StatusOK )
65+ id := createExec (c , "test" )
66+ startExec (id , http .StatusOK )
7667
77- id : = createExec ()
68+ id = createExec (c , "test" )
7869 dockerCmd (c , "stop" , "test" )
7970
8071 startExec (id , http .StatusNotFound )
@@ -83,9 +74,33 @@ func (s *DockerSuite) TestExecAPIStart(c *check.C) {
8374 startExec (id , http .StatusNotFound )
8475
8576 // make sure exec is created before pausing
86- id = createExec ()
77+ id = createExec (c , "test" )
8778 dockerCmd (c , "pause" , "test" )
8879 startExec (id , http .StatusConflict )
8980 dockerCmd (c , "unpause" , "test" )
9081 startExec (id , http .StatusOK )
9182}
83+
84+ func (s * DockerSuite ) TestExecAPIStartBackwardsCompatible (c * check.C ) {
85+ dockerCmd (c , "run" , "-d" , "--name" , "test" , "busybox" , "top" )
86+ id := createExec (c , "test" )
87+
88+ resp , body , err := sockRequestRaw ("POST" , fmt .Sprintf ("/v1.20/exec/%s/start" , id ), strings .NewReader (`{"Detach": true}` ), "text/plain" )
89+ c .Assert (err , check .IsNil )
90+
91+ b , err := readBody (body )
92+ comment := check .Commentf ("response body: %s" , b )
93+ c .Assert (err , check .IsNil , comment )
94+ c .Assert (resp .StatusCode , check .Equals , http .StatusOK , comment )
95+ }
96+
97+ func createExec (c * check.C , name string ) string {
98+ _ , b , err := sockRequest ("POST" , fmt .Sprintf ("/containers/%s/exec" , name ), map [string ]interface {}{"Cmd" : []string {"true" }})
99+ c .Assert (err , check .IsNil , check .Commentf (string (b )))
100+
101+ createResp := struct {
102+ ID string `json:"Id"`
103+ }{}
104+ c .Assert (json .Unmarshal (b , & createResp ), check .IsNil , check .Commentf (string (b )))
105+ return createResp .ID
106+ }
0 commit comments