Signed-off-by: Megan Kostick <mkostick@us.ibm.com>
| ... | ... |
@@ -28,10 +28,9 @@ func (s *DockerSuite) TestContainerApiGetAll(c *check.C) {
|
| 28 | 28 |
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
- _, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
| 32 |
- if err != nil {
|
|
| 33 |
- c.Fatalf("GET all containers sockRequest failed: %v", err)
|
|
| 34 |
- } |
|
| 31 |
+ status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
| 32 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 33 |
+ c.Assert(err, check.IsNil) |
|
| 35 | 34 |
|
| 36 | 35 |
var inspectJSON []struct {
|
| 37 | 36 |
Names []string |
| ... | ... |
@@ -57,10 +56,9 @@ func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
|
| 57 | 57 |
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 |
- _, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
|
| 61 |
- if err != nil {
|
|
| 62 |
- c.Fatalf("GET containers/export sockRequest failed: %v", err)
|
|
| 63 |
- } |
|
| 60 |
+ status, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
|
|
| 61 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 62 |
+ c.Assert(err, check.IsNil) |
|
| 64 | 63 |
|
| 65 | 64 |
found := false |
| 66 | 65 |
for tarReader := tar.NewReader(bytes.NewReader(body)); ; {
|
| ... | ... |
@@ -90,10 +88,9 @@ func (s *DockerSuite) TestContainerApiGetChanges(c *check.C) {
|
| 90 | 90 |
c.Fatalf("Error on container creation: %v, output: %q", err, out)
|
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 |
- _, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
|
| 94 |
- if err != nil {
|
|
| 95 |
- c.Fatalf("GET containers/changes sockRequest failed: %v", err)
|
|
| 96 |
- } |
|
| 93 |
+ status, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
|
|
| 94 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 95 |
+ c.Assert(err, check.IsNil) |
|
| 97 | 96 |
|
| 98 | 97 |
changes := []struct {
|
| 99 | 98 |
Kind int |
| ... | ... |
@@ -122,17 +119,17 @@ func (s *DockerSuite) TestContainerApiStartVolumeBinds(c *check.C) {
|
| 122 | 122 |
"Volumes": map[string]struct{}{"/tmp": {}},
|
| 123 | 123 |
} |
| 124 | 124 |
|
| 125 |
- if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
|
| 126 |
- c.Fatal(err) |
|
| 127 |
- } |
|
| 125 |
+ status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 126 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 127 |
+ c.Assert(err, check.IsNil) |
|
| 128 | 128 |
|
| 129 | 129 |
bindPath := randomUnixTmpDirPath("test")
|
| 130 | 130 |
config = map[string]interface{}{
|
| 131 | 131 |
"Binds": []string{bindPath + ":/tmp"},
|
| 132 | 132 |
} |
| 133 |
- if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
|
|
| 134 |
- c.Fatal(err) |
|
| 135 |
- } |
|
| 133 |
+ status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
|
|
| 134 |
+ c.Assert(status, check.Equals, http.StatusNoContent) |
|
| 135 |
+ c.Assert(err, check.IsNil) |
|
| 136 | 136 |
|
| 137 | 137 |
pth, err := inspectFieldMap(name, "Volumes", "/tmp") |
| 138 | 138 |
if err != nil {
|
| ... | ... |
@@ -152,9 +149,9 @@ func (s *DockerSuite) TestContainerApiStartDupVolumeBinds(c *check.C) {
|
| 152 | 152 |
"Volumes": map[string]struct{}{"/tmp": {}},
|
| 153 | 153 |
} |
| 154 | 154 |
|
| 155 |
- if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
|
| 156 |
- c.Fatal(err) |
|
| 157 |
- } |
|
| 155 |
+ status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 156 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 157 |
+ c.Assert(err, check.IsNil) |
|
| 158 | 158 |
|
| 159 | 159 |
bindPath1 := randomUnixTmpDirPath("test1")
|
| 160 | 160 |
bindPath2 := randomUnixTmpDirPath("test2")
|
| ... | ... |
@@ -162,14 +159,15 @@ func (s *DockerSuite) TestContainerApiStartDupVolumeBinds(c *check.C) {
|
| 162 | 162 |
config = map[string]interface{}{
|
| 163 | 163 |
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
|
| 164 | 164 |
} |
| 165 |
- if _, body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
|
|
| 166 |
- c.Fatal("expected container start to fail when duplicate volume binds to same container path")
|
|
| 167 |
- } else {
|
|
| 168 |
- if !strings.Contains(string(body), "Duplicate volume") {
|
|
| 169 |
- c.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
|
|
| 170 |
- } |
|
| 165 |
+ status, body, err := sockRequest("POST", "/containers/"+name+"/start", config)
|
|
| 166 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 167 |
+ c.Assert(err, check.IsNil) |
|
| 168 |
+ |
|
| 169 |
+ if !strings.Contains(string(body), "Duplicate volume") {
|
|
| 170 |
+ c.Fatalf("Expected failure due to duplicate bind mounts to same path, instead got: %q with error: %v", string(body), err)
|
|
| 171 | 171 |
} |
| 172 | 172 |
} |
| 173 |
+ |
|
| 173 | 174 |
func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
|
| 174 | 175 |
volName := "voltst" |
| 175 | 176 |
volPath := "/tmp" |
| ... | ... |
@@ -184,16 +182,16 @@ func (s *DockerSuite) TestContainerApiStartVolumesFrom(c *check.C) {
|
| 184 | 184 |
"Volumes": map[string]struct{}{volPath: {}},
|
| 185 | 185 |
} |
| 186 | 186 |
|
| 187 |
- if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
|
| 188 |
- c.Fatal(err) |
|
| 189 |
- } |
|
| 187 |
+ status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 188 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 189 |
+ c.Assert(err, check.IsNil) |
|
| 190 | 190 |
|
| 191 | 191 |
config = map[string]interface{}{
|
| 192 | 192 |
"VolumesFrom": []string{volName},
|
| 193 | 193 |
} |
| 194 |
- if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
|
|
| 195 |
- c.Fatal(err) |
|
| 196 |
- } |
|
| 194 |
+ status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
|
|
| 195 |
+ c.Assert(status, check.Equals, http.StatusNoContent) |
|
| 196 |
+ c.Assert(err, check.IsNil) |
|
| 197 | 197 |
|
| 198 | 198 |
pth, err := inspectFieldMap(name, "Volumes", volPath) |
| 199 | 199 |
if err != nil {
|
| ... | ... |
@@ -225,18 +223,18 @@ func (s *DockerSuite) TestVolumesFromHasPriority(c *check.C) {
|
| 225 | 225 |
"Volumes": map[string]struct{}{volPath: {}},
|
| 226 | 226 |
} |
| 227 | 227 |
|
| 228 |
- if status, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && status != http.StatusCreated {
|
|
| 229 |
- c.Fatal(err) |
|
| 230 |
- } |
|
| 228 |
+ status, _, err := sockRequest("POST", "/containers/create?name="+name, config)
|
|
| 229 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 230 |
+ c.Assert(err, check.IsNil) |
|
| 231 | 231 |
|
| 232 | 232 |
bindPath := randomUnixTmpDirPath("test")
|
| 233 | 233 |
config = map[string]interface{}{
|
| 234 | 234 |
"VolumesFrom": []string{volName},
|
| 235 | 235 |
"Binds": []string{bindPath + ":/tmp"},
|
| 236 | 236 |
} |
| 237 |
- if status, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && status != http.StatusNoContent {
|
|
| 238 |
- c.Fatal(err) |
|
| 239 |
- } |
|
| 237 |
+ status, _, err = sockRequest("POST", "/containers/"+name+"/start", config)
|
|
| 238 |
+ c.Assert(status, check.Equals, http.StatusNoContent) |
|
| 239 |
+ c.Assert(err, check.IsNil) |
|
| 240 | 240 |
|
| 241 | 241 |
pth, err := inspectFieldMap(name, "Volumes", volPath) |
| 242 | 242 |
if err != nil {
|
| ... | ... |
@@ -267,7 +265,9 @@ func (s *DockerSuite) TestGetContainerStats(c *check.C) {
|
| 267 | 267 |
} |
| 268 | 268 |
bc := make(chan b, 1) |
| 269 | 269 |
go func() {
|
| 270 |
- _, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 270 |
+ status, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 271 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 272 |
+ c.Assert(err, check.IsNil) |
|
| 271 | 273 |
bc <- b{body, err}
|
| 272 | 274 |
}() |
| 273 | 275 |
|
| ... | ... |
@@ -309,10 +309,9 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
| 309 | 309 |
go func() {
|
| 310 | 310 |
// We'll never get return for GET stats from sockRequest as of now, |
| 311 | 311 |
// just send request and see if panic or error would happen on daemon side. |
| 312 |
- _, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 313 |
- if err != nil {
|
|
| 314 |
- c.Fatal(err) |
|
| 315 |
- } |
|
| 312 |
+ status, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
|
|
| 313 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 314 |
+ c.Assert(err, check.IsNil) |
|
| 316 | 315 |
}() |
| 317 | 316 |
|
| 318 | 317 |
// allow some time to send request and let daemon deal with it |
| ... | ... |
@@ -340,11 +339,10 @@ func (s *DockerSuite) TestBuildApiDockerfilePath(c *check.C) {
|
| 340 | 340 |
c.Fatalf("failed to close tar archive: %v", err)
|
| 341 | 341 |
} |
| 342 | 342 |
|
| 343 |
- _, body, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
|
|
| 344 |
- if err == nil {
|
|
| 345 |
- out, _ := readBody(body) |
|
| 346 |
- c.Fatalf("Build was supposed to fail: %s", out)
|
|
| 347 |
- } |
|
| 343 |
+ status, body, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
|
|
| 344 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 345 |
+ c.Assert(err, check.IsNil) |
|
| 346 |
+ |
|
| 348 | 347 |
out, err := readBody(body) |
| 349 | 348 |
if err != nil {
|
| 350 | 349 |
c.Fatal(err) |
| ... | ... |
@@ -367,10 +365,10 @@ RUN find /tmp/`, |
| 367 | 367 |
} |
| 368 | 368 |
defer server.Close() |
| 369 | 369 |
|
| 370 |
- _, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
|
|
| 371 |
- if err != nil {
|
|
| 372 |
- c.Fatalf("Build failed: %s", err)
|
|
| 373 |
- } |
|
| 370 |
+ status, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
|
|
| 371 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 372 |
+ c.Assert(err, check.IsNil) |
|
| 373 |
+ |
|
| 374 | 374 |
buf, err := readBody(body) |
| 375 | 375 |
if err != nil {
|
| 376 | 376 |
c.Fatal(err) |
| ... | ... |
@@ -395,11 +393,10 @@ RUN echo from dockerfile`, |
| 395 | 395 |
} |
| 396 | 396 |
defer git.Close() |
| 397 | 397 |
|
| 398 |
- _, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
| 399 |
- if err != nil {
|
|
| 400 |
- buf, _ := readBody(body) |
|
| 401 |
- c.Fatalf("Build failed: %s\n%q", err, buf)
|
|
| 402 |
- } |
|
| 398 |
+ status, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
| 399 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 400 |
+ c.Assert(err, check.IsNil) |
|
| 401 |
+ |
|
| 403 | 402 |
buf, err := readBody(body) |
| 404 | 403 |
if err != nil {
|
| 405 | 404 |
c.Fatal(err) |
| ... | ... |
@@ -424,11 +421,10 @@ RUN echo from Dockerfile`, |
| 424 | 424 |
defer git.Close() |
| 425 | 425 |
|
| 426 | 426 |
// Make sure it tries to 'dockerfile' query param value |
| 427 |
- _, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
|
|
| 428 |
- if err != nil {
|
|
| 429 |
- buf, _ := readBody(body) |
|
| 430 |
- c.Fatalf("Build failed: %s\n%q", err, buf)
|
|
| 431 |
- } |
|
| 427 |
+ status, body, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
|
|
| 428 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 429 |
+ c.Assert(err, check.IsNil) |
|
| 430 |
+ |
|
| 432 | 431 |
buf, err := readBody(body) |
| 433 | 432 |
if err != nil {
|
| 434 | 433 |
c.Fatal(err) |
| ... | ... |
@@ -454,10 +450,10 @@ RUN echo from dockerfile`, |
| 454 | 454 |
defer git.Close() |
| 455 | 455 |
|
| 456 | 456 |
// Make sure it tries to 'dockerfile' query param value |
| 457 |
- _, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
| 458 |
- if err != nil {
|
|
| 459 |
- c.Fatalf("Build failed: %s", err)
|
|
| 460 |
- } |
|
| 457 |
+ status, body, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
|
|
| 458 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 459 |
+ c.Assert(err, check.IsNil) |
|
| 460 |
+ |
|
| 461 | 461 |
buf, err := readBody(body) |
| 462 | 462 |
if err != nil {
|
| 463 | 463 |
c.Fatal(err) |
| ... | ... |
@@ -487,11 +483,10 @@ func (s *DockerSuite) TestBuildApiDockerfileSymlink(c *check.C) {
|
| 487 | 487 |
c.Fatalf("failed to close tar archive: %v", err)
|
| 488 | 488 |
} |
| 489 | 489 |
|
| 490 |
- _, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
|
|
| 491 |
- if err == nil {
|
|
| 492 |
- out, _ := readBody(body) |
|
| 493 |
- c.Fatalf("Build was supposed to fail: %s", out)
|
|
| 494 |
- } |
|
| 490 |
+ status, body, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
|
|
| 491 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 492 |
+ c.Assert(err, check.IsNil) |
|
| 493 |
+ |
|
| 495 | 494 |
out, err := readBody(body) |
| 496 | 495 |
if err != nil {
|
| 497 | 496 |
c.Fatal(err) |
| ... | ... |
@@ -524,9 +519,9 @@ func (s *DockerSuite) TestPostContainerBindNormalVolume(c *check.C) {
|
| 524 | 524 |
} |
| 525 | 525 |
|
| 526 | 526 |
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
|
| 527 |
- if status, _, err := sockRequest("POST", "/containers/two/start", bindSpec); err != nil && status != http.StatusNoContent {
|
|
| 528 |
- c.Fatal(err) |
|
| 529 |
- } |
|
| 527 |
+ status, _, err := sockRequest("POST", "/containers/two/start", bindSpec)
|
|
| 528 |
+ c.Assert(status, check.Equals, http.StatusNoContent) |
|
| 529 |
+ c.Assert(err, check.IsNil) |
|
| 530 | 530 |
|
| 531 | 531 |
fooDir2, err := inspectFieldMap("two", "Volumes", "/foo")
|
| 532 | 532 |
if err != nil {
|
| ... | ... |
@@ -548,9 +543,9 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
|
| 548 | 548 |
} |
| 549 | 549 |
ContainerID := strings.TrimSpace(out) |
| 550 | 550 |
|
| 551 |
- if status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && status != http.StatusNoContent {
|
|
| 552 |
- c.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
|
| 553 |
- } |
|
| 551 |
+ status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/pause", nil)
|
|
| 552 |
+ c.Assert(status, check.Equals, http.StatusNoContent) |
|
| 553 |
+ c.Assert(err, check.IsNil) |
|
| 554 | 554 |
|
| 555 | 555 |
pausedContainers, err := getSliceOfPausedContainers() |
| 556 | 556 |
|
| ... | ... |
@@ -562,9 +557,9 @@ func (s *DockerSuite) TestContainerApiPause(c *check.C) {
|
| 562 | 562 |
c.Fatalf("there should be one paused container and not %d", len(pausedContainers))
|
| 563 | 563 |
} |
| 564 | 564 |
|
| 565 |
- if status, _, err := sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && status != http.StatusNoContent {
|
|
| 566 |
- c.Fatalf("POST a container pause: sockRequest failed: %v", err)
|
|
| 567 |
- } |
|
| 565 |
+ status, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil)
|
|
| 566 |
+ c.Assert(status, check.Equals, http.StatusNoContent) |
|
| 567 |
+ c.Assert(err, check.IsNil) |
|
| 568 | 568 |
|
| 569 | 569 |
pausedContainers, err = getSliceOfPausedContainers() |
| 570 | 570 |
|
| ... | ... |
@@ -592,10 +587,10 @@ func (s *DockerSuite) TestContainerApiTop(c *check.C) {
|
| 592 | 592 |
Processes [][]string |
| 593 | 593 |
} |
| 594 | 594 |
var top topResp |
| 595 |
- _, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
|
|
| 596 |
- if err != nil {
|
|
| 597 |
- c.Fatal(err) |
|
| 598 |
- } |
|
| 595 |
+ status, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
|
|
| 596 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 597 |
+ c.Assert(err, check.IsNil) |
|
| 598 |
+ |
|
| 599 | 599 |
if err := json.Unmarshal(b, &top); err != nil {
|
| 600 | 600 |
c.Fatal(err) |
| 601 | 601 |
} |
| ... | ... |
@@ -626,10 +621,9 @@ func (s *DockerSuite) TestContainerApiCommit(c *check.C) {
|
| 626 | 626 |
id := strings.TrimSpace(string(out)) |
| 627 | 627 |
|
| 628 | 628 |
name := "testcommit" + stringid.GenerateRandomID() |
| 629 |
- _, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+id, nil)
|
|
| 630 |
- if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
|
| 631 |
- c.Fatal(err) |
|
| 632 |
- } |
|
| 629 |
+ status, b, err := sockRequest("POST", "/commit?repo="+name+"&testtag=tag&container="+id, nil)
|
|
| 630 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 631 |
+ c.Assert(err, check.IsNil) |
|
| 633 | 632 |
|
| 634 | 633 |
type resp struct {
|
| 635 | 634 |
Id string |
| ... | ... |
@@ -660,10 +654,10 @@ func (s *DockerSuite) TestContainerApiCreate(c *check.C) {
|
| 660 | 660 |
"Cmd": []string{"/bin/sh", "-c", "touch /test && ls /test"},
|
| 661 | 661 |
} |
| 662 | 662 |
|
| 663 |
- _, b, err := sockRequest("POST", "/containers/create", config)
|
|
| 664 |
- if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
|
| 665 |
- c.Fatal(err) |
|
| 666 |
- } |
|
| 663 |
+ status, b, err := sockRequest("POST", "/containers/create", config)
|
|
| 664 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 665 |
+ c.Assert(err, check.IsNil) |
|
| 666 |
+ |
|
| 667 | 667 |
type createResp struct {
|
| 668 | 668 |
Id string |
| 669 | 669 |
} |
| ... | ... |
@@ -736,26 +730,21 @@ func (s *DockerSuite) TestContainerApiVerifyHeader(c *check.C) {
|
| 736 | 736 |
} |
| 737 | 737 |
|
| 738 | 738 |
// Try with no content-type |
| 739 |
- _, body, err := create("")
|
|
| 740 |
- if err == nil {
|
|
| 741 |
- b, _ := readBody(body) |
|
| 742 |
- c.Fatalf("expected error when content-type is not set: %q", string(b))
|
|
| 743 |
- } |
|
| 739 |
+ status, body, err := create("")
|
|
| 740 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 741 |
+ c.Assert(err, check.IsNil) |
|
| 744 | 742 |
body.Close() |
| 743 |
+ |
|
| 745 | 744 |
// Try with wrong content-type |
| 746 |
- _, body, err = create("application/xml")
|
|
| 747 |
- if err == nil {
|
|
| 748 |
- b, _ := readBody(body) |
|
| 749 |
- c.Fatalf("expected error when content-type is not set: %q", string(b))
|
|
| 750 |
- } |
|
| 745 |
+ status, body, err = create("application/xml")
|
|
| 746 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 747 |
+ c.Assert(err, check.IsNil) |
|
| 751 | 748 |
body.Close() |
| 752 | 749 |
|
| 753 | 750 |
// now application/json |
| 754 |
- _, body, err = create("application/json")
|
|
| 755 |
- if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
|
| 756 |
- b, _ := readBody(body) |
|
| 757 |
- c.Fatalf("%v - %q", err, string(b))
|
|
| 758 |
- } |
|
| 751 |
+ status, body, err = create("application/json")
|
|
| 752 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 753 |
+ c.Assert(err, check.IsNil) |
|
| 759 | 754 |
body.Close() |
| 760 | 755 |
} |
| 761 | 756 |
|
| ... | ... |
@@ -786,11 +775,9 @@ func (s *DockerSuite) TestContainerApiPostCreateNull(c *check.C) {
|
| 786 | 786 |
"NetworkDisabled":false, |
| 787 | 787 |
"OnBuild":null}` |
| 788 | 788 |
|
| 789 |
- _, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 790 |
- if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
|
| 791 |
- b, _ := readBody(body) |
|
| 792 |
- c.Fatal(err, string(b)) |
|
| 793 |
- } |
|
| 789 |
+ status, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 790 |
+ c.Assert(status, check.Equals, http.StatusCreated) |
|
| 791 |
+ c.Assert(err, check.IsNil) |
|
| 794 | 792 |
|
| 795 | 793 |
b, err := readBody(body) |
| 796 | 794 |
if err != nil {
|
| ... | ... |
@@ -822,16 +809,14 @@ func (s *DockerSuite) TestCreateWithTooLowMemoryLimit(c *check.C) {
|
| 822 | 822 |
"Memory": 524287 |
| 823 | 823 |
}` |
| 824 | 824 |
|
| 825 |
- _, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 825 |
+ status, body, _ := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
|
| 826 | 826 |
b, err2 := readBody(body) |
| 827 | 827 |
if err2 != nil {
|
| 828 | 828 |
c.Fatal(err2) |
| 829 | 829 |
} |
| 830 | 830 |
|
| 831 |
- if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
|
|
| 832 |
- c.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
|
|
| 833 |
- } |
|
| 834 |
- |
|
| 831 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 832 |
+ c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true) |
|
| 835 | 833 |
} |
| 836 | 834 |
|
| 837 | 835 |
func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
|
| ... | ... |
@@ -847,13 +832,12 @@ func (s *DockerSuite) TestStartWithTooLowMemoryLimit(c *check.C) {
|
| 847 | 847 |
"Memory": 524287 |
| 848 | 848 |
}` |
| 849 | 849 |
|
| 850 |
- _, body, err := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
|
|
| 850 |
+ status, body, _ := sockRequestRaw("POST", "/containers/"+containerID+"/start", strings.NewReader(config), "application/json")
|
|
| 851 | 851 |
b, err2 := readBody(body) |
| 852 | 852 |
if err2 != nil {
|
| 853 | 853 |
c.Fatal(err2) |
| 854 | 854 |
} |
| 855 | 855 |
|
| 856 |
- if err == nil || !strings.Contains(string(b), "Minimum memory limit allowed is 4MB") {
|
|
| 857 |
- c.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
|
|
| 858 |
- } |
|
| 856 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 857 |
+ c.Assert(strings.Contains(string(b), "Minimum memory limit allowed is 4MB"), check.Equals, true) |
|
| 859 | 858 |
} |
| ... | ... |
@@ -18,10 +18,6 @@ func (s *DockerSuite) TestExecResizeApiHeightWidthNoInt(c *check.C) {
|
| 18 | 18 |
|
| 19 | 19 |
endpoint := "/exec/" + cleanedContainerID + "/resize?h=foo&w=bar" |
| 20 | 20 |
status, _, err := sockRequest("POST", endpoint, nil)
|
| 21 |
- if err == nil {
|
|
| 22 |
- c.Fatal("Expected exec resize Request to fail")
|
|
| 23 |
- } |
|
| 24 |
- if status != http.StatusInternalServerError {
|
|
| 25 |
- c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
|
|
| 26 |
- } |
|
| 21 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 22 |
+ c.Assert(err, check.IsNil) |
|
| 27 | 23 |
} |
| ... | ... |
@@ -5,6 +5,7 @@ package main |
| 5 | 5 |
import ( |
| 6 | 6 |
"bytes" |
| 7 | 7 |
"fmt" |
| 8 |
+ "net/http" |
|
| 8 | 9 |
"os/exec" |
| 9 | 10 |
|
| 10 | 11 |
"github.com/go-check/check" |
| ... | ... |
@@ -18,8 +19,11 @@ func (s *DockerSuite) TestExecApiCreateNoCmd(c *check.C) {
|
| 18 | 18 |
c.Fatal(out, err) |
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 |
- _, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
|
| 22 |
- if err == nil || !bytes.Contains(body, []byte("No exec command specified")) {
|
|
| 23 |
- c.Fatalf("Expected error when creating exec command with no Cmd specified: %q", err)
|
|
| 21 |
+ status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
|
|
| 22 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 23 |
+ c.Assert(err, check.IsNil) |
|
| 24 |
+ |
|
| 25 |
+ if !bytes.Contains(body, []byte("No exec command specified")) {
|
|
| 26 |
+ c.Fatalf("Expected message when creating exec command with no Cmd specified")
|
|
| 24 | 27 |
} |
| 25 | 28 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
+ "net/http" |
|
| 5 | 6 |
"net/url" |
| 6 | 7 |
"os/exec" |
| 7 | 8 |
"strings" |
| ... | ... |
@@ -11,10 +12,9 @@ import ( |
| 11 | 11 |
) |
| 12 | 12 |
|
| 13 | 13 |
func (s *DockerSuite) TestLegacyImages(c *check.C) {
|
| 14 |
- _, body, err := sockRequest("GET", "/v1.6/images/json", nil)
|
|
| 15 |
- if err != nil {
|
|
| 16 |
- c.Fatalf("Error on GET: %s", err)
|
|
| 17 |
- } |
|
| 14 |
+ status, body, err := sockRequest("GET", "/v1.6/images/json", nil)
|
|
| 15 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 16 |
+ c.Assert(err, check.IsNil) |
|
| 18 | 17 |
|
| 19 | 18 |
images := []types.LegacyImage{}
|
| 20 | 19 |
if err = json.Unmarshal(body, &images); err != nil {
|
| ... | ... |
@@ -40,10 +40,10 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
| 40 | 40 |
getImages := func(filter string) []image {
|
| 41 | 41 |
v := url.Values{}
|
| 42 | 42 |
v.Set("filter", filter)
|
| 43 |
- _, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
|
| 44 |
- if err != nil {
|
|
| 45 |
- c.Fatal(err) |
|
| 46 |
- } |
|
| 43 |
+ status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
|
| 44 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 45 |
+ c.Assert(err, check.IsNil) |
|
| 46 |
+ |
|
| 47 | 47 |
var images []image |
| 48 | 48 |
if err := json.Unmarshal(b, &images); err != nil {
|
| 49 | 49 |
c.Fatal(err) |
| ... | ... |
@@ -76,20 +76,20 @@ func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
| 76 | 76 |
id := strings.TrimSpace(out) |
| 77 | 77 |
defer deleteImages("saveandload")
|
| 78 | 78 |
|
| 79 |
- _, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
|
| 80 |
- if err != nil {
|
|
| 81 |
- c.Fatal(err) |
|
| 82 |
- } |
|
| 79 |
+ status, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
|
| 80 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 81 |
+ c.Assert(err, check.IsNil) |
|
| 82 |
+ |
|
| 83 | 83 |
defer body.Close() |
| 84 | 84 |
|
| 85 | 85 |
if out, err := exec.Command(dockerBinary, "rmi", id).CombinedOutput(); err != nil {
|
| 86 | 86 |
c.Fatal(err, out) |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 |
- _, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
|
| 90 |
- if err != nil {
|
|
| 91 |
- c.Fatal(err) |
|
| 92 |
- } |
|
| 89 |
+ status, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
|
| 90 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 91 |
+ c.Assert(err, check.IsNil) |
|
| 92 |
+ |
|
| 93 | 93 |
defer loadBody.Close() |
| 94 | 94 |
|
| 95 | 95 |
inspectOut, err := exec.Command(dockerBinary, "inspect", "--format='{{ .Id }}'", id).CombinedOutput()
|
| ... | ... |
@@ -10,10 +10,9 @@ import ( |
| 10 | 10 |
func (s *DockerSuite) TestInfoApi(c *check.C) {
|
| 11 | 11 |
endpoint := "/info" |
| 12 | 12 |
|
| 13 |
- statusCode, body, err := sockRequest("GET", endpoint, nil)
|
|
| 14 |
- if err != nil || statusCode != http.StatusOK {
|
|
| 15 |
- c.Fatalf("Expected %d from info request, got %d", http.StatusOK, statusCode)
|
|
| 16 |
- } |
|
| 13 |
+ status, body, err := sockRequest("GET", endpoint, nil)
|
|
| 14 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 15 |
+ c.Assert(err, check.IsNil) |
|
| 17 | 16 |
|
| 18 | 17 |
// always shown fields |
| 19 | 18 |
stringsToCheck := []string{
|
| ... | ... |
@@ -2,6 +2,7 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
+ "net/http" |
|
| 5 | 6 |
"os/exec" |
| 6 | 7 |
"strings" |
| 7 | 8 |
|
| ... | ... |
@@ -26,10 +27,9 @@ func (s *DockerSuite) TestInspectApiContainerResponse(c *check.C) {
|
| 26 | 26 |
if testVersion != "latest" {
|
| 27 | 27 |
endpoint = "/" + testVersion + endpoint |
| 28 | 28 |
} |
| 29 |
- _, body, err := sockRequest("GET", endpoint, nil)
|
|
| 30 |
- if err != nil {
|
|
| 31 |
- c.Fatalf("sockRequest failed for %s version: %v", testVersion, err)
|
|
| 32 |
- } |
|
| 29 |
+ status, body, err := sockRequest("GET", endpoint, nil)
|
|
| 30 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 31 |
+ c.Assert(err, check.IsNil) |
|
| 33 | 32 |
|
| 34 | 33 |
var inspectJSON map[string]interface{}
|
| 35 | 34 |
if err = json.Unmarshal(body, &inspectJSON); err != nil {
|
| ... | ... |
@@ -17,11 +17,9 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
|
| 17 | 17 |
c.Fatal(out, err) |
| 18 | 18 |
} |
| 19 | 19 |
|
| 20 |
- statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", name), nil)
|
|
| 21 |
- |
|
| 22 |
- if err != nil || statusCode != http.StatusOK {
|
|
| 23 |
- c.Fatalf("Expected %d from logs request, got %d", http.StatusOK, statusCode)
|
|
| 24 |
- } |
|
| 20 |
+ status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", name), nil)
|
|
| 21 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 22 |
+ c.Assert(err, check.IsNil) |
|
| 25 | 23 |
|
| 26 | 24 |
if !bytes.Contains(body, []byte(name)) {
|
| 27 | 25 |
c.Fatalf("Expected %s, got %s", name, string(body[:]))
|
| ... | ... |
@@ -35,11 +33,9 @@ func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
|
| 35 | 35 |
c.Fatal(out, err) |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
- statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
|
|
| 39 |
- |
|
| 40 |
- if err == nil || statusCode != http.StatusBadRequest {
|
|
| 41 |
- c.Fatalf("Expected %d from logs request, got %d", http.StatusBadRequest, statusCode)
|
|
| 42 |
- } |
|
| 38 |
+ status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
|
|
| 39 |
+ c.Assert(status, check.Equals, http.StatusBadRequest) |
|
| 40 |
+ c.Assert(err, check.IsNil) |
|
| 43 | 41 |
|
| 44 | 42 |
expected := "Bad parameters: you must choose at least one stream" |
| 45 | 43 |
if !bytes.Contains(body, []byte(expected)) {
|
| ... | ... |
@@ -17,10 +17,9 @@ func (s *DockerSuite) TestResizeApiResponse(c *check.C) {
|
| 17 | 17 |
cleanedContainerID := strings.TrimSpace(out) |
| 18 | 18 |
|
| 19 | 19 |
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" |
| 20 |
- _, _, err = sockRequest("POST", endpoint, nil)
|
|
| 21 |
- if err != nil {
|
|
| 22 |
- c.Fatalf("resize Request failed %v", err)
|
|
| 23 |
- } |
|
| 20 |
+ status, _, err := sockRequest("POST", endpoint, nil)
|
|
| 21 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 22 |
+ c.Assert(err, check.IsNil) |
|
| 24 | 23 |
} |
| 25 | 24 |
|
| 26 | 25 |
func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
|
| ... | ... |
@@ -33,12 +32,8 @@ func (s *DockerSuite) TestResizeApiHeightWidthNoInt(c *check.C) {
|
| 33 | 33 |
|
| 34 | 34 |
endpoint := "/containers/" + cleanedContainerID + "/resize?h=foo&w=bar" |
| 35 | 35 |
status, _, err := sockRequest("POST", endpoint, nil)
|
| 36 |
- if err == nil {
|
|
| 37 |
- c.Fatal("Expected resize Request to fail")
|
|
| 38 |
- } |
|
| 39 |
- if status != http.StatusInternalServerError {
|
|
| 40 |
- c.Fatalf("Status expected %d, got %d", http.StatusInternalServerError, status)
|
|
| 41 |
- } |
|
| 36 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 37 |
+ c.Assert(err, check.IsNil) |
|
| 42 | 38 |
} |
| 43 | 39 |
|
| 44 | 40 |
func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
|
| ... | ... |
@@ -57,10 +52,10 @@ func (s *DockerSuite) TestResizeApiResponseWhenContainerNotStarted(c *check.C) {
|
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40" |
| 60 |
- _, body, err := sockRequest("POST", endpoint, nil)
|
|
| 61 |
- if err == nil {
|
|
| 62 |
- c.Fatalf("resize should fail when container is not started")
|
|
| 63 |
- } |
|
| 60 |
+ status, body, err := sockRequest("POST", endpoint, nil)
|
|
| 61 |
+ c.Assert(status, check.Equals, http.StatusInternalServerError) |
|
| 62 |
+ c.Assert(err, check.IsNil) |
|
| 63 |
+ |
|
| 64 | 64 |
if !strings.Contains(string(body), "Cannot resize container") && !strings.Contains(string(body), cleanedContainerID) {
|
| 65 | 65 |
c.Fatalf("resize should fail with message 'Cannot resize container' but instead received %s", string(body))
|
| 66 | 66 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
+ "net/http" |
|
| 5 | 6 |
|
| 6 | 7 |
"github.com/docker/docker/api/types" |
| 7 | 8 |
"github.com/docker/docker/autogen/dockerversion" |
| ... | ... |
@@ -9,10 +10,10 @@ import ( |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 | 11 |
func (s *DockerSuite) TestGetVersion(c *check.C) {
|
| 12 |
- _, body, err := sockRequest("GET", "/version", nil)
|
|
| 13 |
- if err != nil {
|
|
| 14 |
- c.Fatal(err) |
|
| 15 |
- } |
|
| 12 |
+ status, body, err := sockRequest("GET", "/version", nil)
|
|
| 13 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 14 |
+ c.Assert(err, check.IsNil) |
|
| 15 |
+ |
|
| 16 | 16 |
var v types.Version |
| 17 | 17 |
if err := json.Unmarshal(body, &v); err != nil {
|
| 18 | 18 |
c.Fatal(err) |
| ... | ... |
@@ -60,13 +60,8 @@ func (s *DockerSuite) TestRmRunningContainerCheckError409(c *check.C) {
|
| 60 | 60 |
|
| 61 | 61 |
endpoint := "/containers/foo" |
| 62 | 62 |
status, _, err := sockRequest("DELETE", endpoint, nil)
|
| 63 |
- |
|
| 64 |
- if err == nil {
|
|
| 65 |
- c.Fatalf("Expected error, can't rm a running container")
|
|
| 66 |
- } else if status != http.StatusConflict {
|
|
| 67 |
- c.Fatalf("Expected error to contain '409 Conflict' but found %s", err)
|
|
| 68 |
- } |
|
| 69 |
- |
|
| 63 |
+ c.Assert(status, check.Equals, http.StatusConflict) |
|
| 64 |
+ c.Assert(err, check.IsNil) |
|
| 70 | 65 |
} |
| 71 | 66 |
|
| 72 | 67 |
func (s *DockerSuite) TestRmForceRemoveRunningContainer(c *check.C) {
|
| ... | ... |
@@ -350,9 +350,6 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) (int, io |
| 350 | 350 |
defer client.Close() |
| 351 | 351 |
return resp.Body.Close() |
| 352 | 352 |
}) |
| 353 |
- if resp.StatusCode != http.StatusOK {
|
|
| 354 |
- return resp.StatusCode, body, fmt.Errorf("received status != 200 OK: %s", resp.Status)
|
|
| 355 |
- } |
|
| 356 | 353 |
|
| 357 | 354 |
return resp.StatusCode, body, err |
| 358 | 355 |
} |
| ... | ... |
@@ -1062,10 +1059,9 @@ func daemonTime(c *check.C) time.Time {
|
| 1062 | 1062 |
return time.Now() |
| 1063 | 1063 |
} |
| 1064 | 1064 |
|
| 1065 |
- _, body, err := sockRequest("GET", "/info", nil)
|
|
| 1066 |
- if err != nil {
|
|
| 1067 |
- c.Fatalf("daemonTime: failed to get /info: %v", err)
|
|
| 1068 |
- } |
|
| 1065 |
+ status, body, err := sockRequest("GET", "/info", nil)
|
|
| 1066 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 1067 |
+ c.Assert(err, check.IsNil) |
|
| 1069 | 1068 |
|
| 1070 | 1069 |
type infoJSON struct {
|
| 1071 | 1070 |
SystemTime string |
| ... | ... |
@@ -58,8 +58,8 @@ var ( |
| 58 | 58 |
func() bool {
|
| 59 | 59 |
if daemonExecDriver == "" {
|
| 60 | 60 |
// get daemon info |
| 61 |
- _, body, err := sockRequest("GET", "/info", nil)
|
|
| 62 |
- if err != nil {
|
|
| 61 |
+ status, body, err := sockRequest("GET", "/info", nil)
|
|
| 62 |
+ if err != nil || status != http.StatusOK {
|
|
| 63 | 63 |
log.Fatalf("sockRequest failed for /info: %v", err)
|
| 64 | 64 |
} |
| 65 | 65 |
|