Signed-off-by: Brian Goff <cpuguy83@gmail.com>
| ... | ... |
@@ -6,6 +6,7 @@ import ( |
| 6 | 6 |
"encoding/json" |
| 7 | 7 |
"io" |
| 8 | 8 |
"net/http" |
| 9 |
+ "net/http/httputil" |
|
| 9 | 10 |
"os" |
| 10 | 11 |
"os/exec" |
| 11 | 12 |
"strings" |
| ... | ... |
@@ -1150,3 +1151,54 @@ func (s *DockerSuite) TestContainerApiDeleteRemoveVolume(c *check.C) {
|
| 1150 | 1150 |
c.Fatalf("expected to get ErrNotExist error, got %v", err)
|
| 1151 | 1151 |
} |
| 1152 | 1152 |
} |
| 1153 |
+ |
|
| 1154 |
+// Regression test for https://github.com/docker/docker/issues/6231 |
|
| 1155 |
+func (s *DockerSuite) TestContainersApiChunkedEncoding(c *check.C) {
|
|
| 1156 |
+ out, _ := dockerCmd(c, "create", "-v", "/foo", "busybox", "true") |
|
| 1157 |
+ id := strings.TrimSpace(out) |
|
| 1158 |
+ |
|
| 1159 |
+ conn, err := sockConn(time.Duration(10 * time.Second)) |
|
| 1160 |
+ if err != nil {
|
|
| 1161 |
+ c.Fatal(err) |
|
| 1162 |
+ } |
|
| 1163 |
+ client := httputil.NewClientConn(conn, nil) |
|
| 1164 |
+ defer client.Close() |
|
| 1165 |
+ |
|
| 1166 |
+ bindCfg := strings.NewReader(`{"Binds": ["/tmp:/foo"]}`)
|
|
| 1167 |
+ req, err := http.NewRequest("POST", "/containers/"+id+"/start", bindCfg)
|
|
| 1168 |
+ if err != nil {
|
|
| 1169 |
+ c.Fatal(err) |
|
| 1170 |
+ } |
|
| 1171 |
+ req.Header.Set("Content-Type", "application/json")
|
|
| 1172 |
+ // This is a cheat to make the http request do chunked encoding |
|
| 1173 |
+ // Otherwise (just setting the Content-Encoding to chunked) net/http will overwrite |
|
| 1174 |
+ // https://golang.org/src/pkg/net/http/request.go?s=11980:12172 |
|
| 1175 |
+ req.ContentLength = -1 |
|
| 1176 |
+ |
|
| 1177 |
+ resp, err := client.Do(req) |
|
| 1178 |
+ if err != nil {
|
|
| 1179 |
+ c.Fatalf("error starting container with chunked encoding: %v", err)
|
|
| 1180 |
+ } |
|
| 1181 |
+ resp.Body.Close() |
|
| 1182 |
+ if resp.StatusCode != 204 {
|
|
| 1183 |
+ c.Fatalf("expected status code 204, got %d", resp.StatusCode)
|
|
| 1184 |
+ } |
|
| 1185 |
+ |
|
| 1186 |
+ out, err = inspectFieldJSON(id, "HostConfig.Binds") |
|
| 1187 |
+ if err != nil {
|
|
| 1188 |
+ c.Fatal(err) |
|
| 1189 |
+ } |
|
| 1190 |
+ |
|
| 1191 |
+ var binds []string |
|
| 1192 |
+ if err := json.NewDecoder(strings.NewReader(out)).Decode(&binds); err != nil {
|
|
| 1193 |
+ c.Fatal(err) |
|
| 1194 |
+ } |
|
| 1195 |
+ if len(binds) != 1 {
|
|
| 1196 |
+ c.Fatalf("got unexpected binds: %v", binds)
|
|
| 1197 |
+ } |
|
| 1198 |
+ |
|
| 1199 |
+ expected := "/tmp:/foo" |
|
| 1200 |
+ if binds[0] != expected {
|
|
| 1201 |
+ c.Fatalf("got incorrect bind spec, wanted %s, got: %s", expected, binds[0])
|
|
| 1202 |
+ } |
|
| 1203 |
+} |