Applying #16756 to integration-cli/docker_api_images_test.go
Signed-off-by: Aditi Rajagopal <arajagopal@us.ibm.com>
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"strings" |
| 8 | 8 |
|
| 9 | 9 |
"github.com/docker/docker/api/types" |
| 10 |
+ "github.com/docker/docker/pkg/integration/checker" |
|
| 10 | 11 |
"github.com/go-check/check" |
| 11 | 12 |
) |
| 12 | 13 |
|
| ... | ... |
@@ -23,59 +24,51 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
| 23 | 23 |
v := url.Values{}
|
| 24 | 24 |
v.Set("filter", filter)
|
| 25 | 25 |
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
| 26 |
- c.Assert(err, check.IsNil) |
|
| 27 |
- c.Assert(status, check.Equals, http.StatusOK) |
|
| 26 |
+ c.Assert(err, checker.IsNil) |
|
| 27 |
+ c.Assert(status, checker.Equals, http.StatusOK) |
|
| 28 | 28 |
|
| 29 | 29 |
var images []image |
| 30 |
- if err := json.Unmarshal(b, &images); err != nil {
|
|
| 31 |
- c.Fatal(err) |
|
| 32 |
- } |
|
| 30 |
+ err = json.Unmarshal(b, &images) |
|
| 31 |
+ c.Assert(err, checker.IsNil) |
|
| 33 | 32 |
|
| 34 | 33 |
return images |
| 35 | 34 |
} |
| 36 | 35 |
|
| 37 |
- errMsg := "incorrect number of matches returned" |
|
| 38 |
- if images := getImages("utest*/*"); len(images[0].RepoTags) != 2 {
|
|
| 39 |
- c.Fatal(errMsg) |
|
| 40 |
- } |
|
| 41 |
- if images := getImages("utest"); len(images[0].RepoTags) != 1 {
|
|
| 42 |
- c.Fatal(errMsg) |
|
| 43 |
- } |
|
| 44 |
- if images := getImages("utest*"); len(images[0].RepoTags) != 1 {
|
|
| 45 |
- c.Fatal(errMsg) |
|
| 46 |
- } |
|
| 47 |
- if images := getImages("*5000*/*"); len(images[0].RepoTags) != 1 {
|
|
| 48 |
- c.Fatal(errMsg) |
|
| 49 |
- } |
|
| 36 |
+ //incorrect number of matches returned |
|
| 37 |
+ images := getImages("utest*/*")
|
|
| 38 |
+ c.Assert(images[0].RepoTags, checker.HasLen, 2) |
|
| 39 |
+ |
|
| 40 |
+ images = getImages("utest")
|
|
| 41 |
+ c.Assert(images[0].RepoTags, checker.HasLen, 1) |
|
| 42 |
+ |
|
| 43 |
+ images = getImages("utest*")
|
|
| 44 |
+ c.Assert(images[0].RepoTags, checker.HasLen, 1) |
|
| 45 |
+ |
|
| 46 |
+ images = getImages("*5000*/*")
|
|
| 47 |
+ c.Assert(images[0].RepoTags, checker.HasLen, 1) |
|
| 50 | 48 |
} |
| 51 | 49 |
|
| 52 | 50 |
func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
| 53 | 51 |
testRequires(c, Network) |
| 54 | 52 |
testRequires(c, DaemonIsLinux) |
| 55 | 53 |
out, err := buildImage("saveandload", "FROM hello-world\nENV FOO bar", false)
|
| 56 |
- if err != nil {
|
|
| 57 |
- c.Fatal(err) |
|
| 58 |
- } |
|
| 54 |
+ c.Assert(err, checker.IsNil) |
|
| 59 | 55 |
id := strings.TrimSpace(out) |
| 60 | 56 |
|
| 61 | 57 |
res, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
| 62 |
- c.Assert(err, check.IsNil) |
|
| 63 |
- c.Assert(res.StatusCode, check.Equals, http.StatusOK) |
|
| 64 |
- |
|
| 58 |
+ c.Assert(err, checker.IsNil) |
|
| 65 | 59 |
defer body.Close() |
| 60 |
+ c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
|
| 66 | 61 |
|
| 67 | 62 |
dockerCmd(c, "rmi", id) |
| 68 | 63 |
|
| 69 | 64 |
res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
| 70 |
- c.Assert(err, check.IsNil) |
|
| 71 |
- c.Assert(res.StatusCode, check.Equals, http.StatusOK) |
|
| 72 |
- |
|
| 65 |
+ c.Assert(err, checker.IsNil) |
|
| 73 | 66 |
defer loadBody.Close() |
| 67 |
+ c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
|
| 74 | 68 |
|
| 75 | 69 |
inspectOut, _ := dockerCmd(c, "inspect", "--format='{{ .Id }}'", id)
|
| 76 |
- if strings.TrimSpace(string(inspectOut)) != id {
|
|
| 77 |
- c.Fatal("load did not work properly")
|
|
| 78 |
- } |
|
| 70 |
+ c.Assert(strings.TrimSpace(string(inspectOut)), checker.Equals, id, check.Commentf("load did not work properly"))
|
|
| 79 | 71 |
} |
| 80 | 72 |
|
| 81 | 73 |
func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
|
| ... | ... |
@@ -83,24 +76,22 @@ func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
|
| 83 | 83 |
testRequires(c, DaemonIsLinux) |
| 84 | 84 |
name := "test-api-images-delete" |
| 85 | 85 |
out, err := buildImage(name, "FROM hello-world\nENV FOO bar", false) |
| 86 |
- if err != nil {
|
|
| 87 |
- c.Fatal(err) |
|
| 88 |
- } |
|
| 86 |
+ c.Assert(err, checker.IsNil) |
|
| 89 | 87 |
id := strings.TrimSpace(out) |
| 90 | 88 |
|
| 91 | 89 |
dockerCmd(c, "tag", name, "test:tag1") |
| 92 | 90 |
|
| 93 | 91 |
status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
| 94 |
- c.Assert(err, check.IsNil) |
|
| 95 |
- c.Assert(status, check.Equals, http.StatusConflict) |
|
| 92 |
+ c.Assert(err, checker.IsNil) |
|
| 93 |
+ c.Assert(status, checker.Equals, http.StatusConflict) |
|
| 96 | 94 |
|
| 97 | 95 |
status, _, err = sockRequest("DELETE", "/images/test:noexist", nil)
|
| 98 |
- c.Assert(err, check.IsNil) |
|
| 99 |
- c.Assert(status, check.Equals, http.StatusNotFound) //Status Codes:404 – no such image |
|
| 96 |
+ c.Assert(err, checker.IsNil) |
|
| 97 |
+ c.Assert(status, checker.Equals, http.StatusNotFound) //Status Codes:404 – no such image |
|
| 100 | 98 |
|
| 101 | 99 |
status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
| 102 |
- c.Assert(err, check.IsNil) |
|
| 103 |
- c.Assert(status, check.Equals, http.StatusOK) |
|
| 100 |
+ c.Assert(err, checker.IsNil) |
|
| 101 |
+ c.Assert(status, checker.Equals, http.StatusOK) |
|
| 104 | 102 |
} |
| 105 | 103 |
|
| 106 | 104 |
func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
| ... | ... |
@@ -108,21 +99,20 @@ func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
| 108 | 108 |
testRequires(c, DaemonIsLinux) |
| 109 | 109 |
name := "test-api-images-history" |
| 110 | 110 |
out, err := buildImage(name, "FROM hello-world\nENV FOO bar", false) |
| 111 |
- c.Assert(err, check.IsNil) |
|
| 111 |
+ c.Assert(err, checker.IsNil) |
|
| 112 | 112 |
|
| 113 | 113 |
id := strings.TrimSpace(out) |
| 114 | 114 |
|
| 115 | 115 |
status, body, err := sockRequest("GET", "/images/"+id+"/history", nil)
|
| 116 |
- c.Assert(err, check.IsNil) |
|
| 117 |
- c.Assert(status, check.Equals, http.StatusOK) |
|
| 116 |
+ c.Assert(err, checker.IsNil) |
|
| 117 |
+ c.Assert(status, checker.Equals, http.StatusOK) |
|
| 118 | 118 |
|
| 119 | 119 |
var historydata []types.ImageHistory |
| 120 |
- if err = json.Unmarshal(body, &historydata); err != nil {
|
|
| 121 |
- c.Fatalf("Error on unmarshal: %s", err)
|
|
| 122 |
- } |
|
| 120 |
+ err = json.Unmarshal(body, &historydata) |
|
| 121 |
+ c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))
|
|
| 123 | 122 |
|
| 124 |
- c.Assert(len(historydata), check.Not(check.Equals), 0) |
|
| 125 |
- c.Assert(historydata[0].Tags[0], check.Equals, "test-api-images-history:latest") |
|
| 123 |
+ c.Assert(historydata, checker.Not(checker.HasLen), 0) |
|
| 124 |
+ c.Assert(historydata[0].Tags[0], checker.Equals, "test-api-images-history:latest") |
|
| 126 | 125 |
} |
| 127 | 126 |
|
| 128 | 127 |
// #14846 |
| ... | ... |
@@ -132,6 +122,6 @@ func (s *DockerSuite) TestApiImagesSearchJSONContentType(c *check.C) {
|
| 132 | 132 |
res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
| 133 | 133 |
c.Assert(err, check.IsNil) |
| 134 | 134 |
b.Close() |
| 135 |
- c.Assert(res.StatusCode, check.Equals, http.StatusOK) |
|
| 136 |
- c.Assert(res.Header.Get("Content-Type"), check.Equals, "application/json")
|
|
| 135 |
+ c.Assert(res.StatusCode, checker.Equals, http.StatusOK) |
|
| 136 |
+ c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json")
|
|
| 137 | 137 |
} |