mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Checkers on integration-cli/docker_api_images_test
Applying #16756 to integration-cli/docker_api_images_test.go Signed-off-by: Aditi Rajagopal <arajagopal@us.ibm.com>
This commit is contained in:
parent
1d1de645fd
commit
463c53c715
1 changed files with 39 additions and 49 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,59 +24,51 @@ func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("filter", filter)
|
v.Set("filter", filter)
|
||||||
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
c.Assert(status, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
var images []image
|
var images []image
|
||||||
if err := json.Unmarshal(b, &images); err != nil {
|
err = json.Unmarshal(b, &images)
|
||||||
c.Fatal(err)
|
c.Assert(err, checker.IsNil)
|
||||||
}
|
|
||||||
|
|
||||||
return images
|
return images
|
||||||
}
|
}
|
||||||
|
|
||||||
errMsg := "incorrect number of matches returned"
|
//incorrect number of matches returned
|
||||||
if images := getImages("utest*/*"); len(images[0].RepoTags) != 2 {
|
images := getImages("utest*/*")
|
||||||
c.Fatal(errMsg)
|
c.Assert(images[0].RepoTags, checker.HasLen, 2)
|
||||||
}
|
|
||||||
if images := getImages("utest"); len(images[0].RepoTags) != 1 {
|
images = getImages("utest")
|
||||||
c.Fatal(errMsg)
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
||||||
}
|
|
||||||
if images := getImages("utest*"); len(images[0].RepoTags) != 1 {
|
images = getImages("utest*")
|
||||||
c.Fatal(errMsg)
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
||||||
}
|
|
||||||
if images := getImages("*5000*/*"); len(images[0].RepoTags) != 1 {
|
images = getImages("*5000*/*")
|
||||||
c.Fatal(errMsg)
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
||||||
testRequires(c, Network)
|
testRequires(c, Network)
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
out, err := buildImage("saveandload", "FROM hello-world\nENV FOO bar", false)
|
out, err := buildImage("saveandload", "FROM hello-world\nENV FOO bar", false)
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil)
|
||||||
c.Fatal(err)
|
|
||||||
}
|
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
|
|
||||||
res, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
res, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
|
||||||
|
|
||||||
defer body.Close()
|
defer body.Close()
|
||||||
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
dockerCmd(c, "rmi", id)
|
dockerCmd(c, "rmi", id)
|
||||||
|
|
||||||
res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
|
||||||
|
|
||||||
defer loadBody.Close()
|
defer loadBody.Close()
|
||||||
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
inspectOut, _ := dockerCmd(c, "inspect", "--format='{{ .Id }}'", id)
|
inspectOut, _ := dockerCmd(c, "inspect", "--format='{{ .Id }}'", id)
|
||||||
if strings.TrimSpace(string(inspectOut)) != id {
|
c.Assert(strings.TrimSpace(string(inspectOut)), checker.Equals, id, check.Commentf("load did not work properly"))
|
||||||
c.Fatal("load did not work properly")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
|
func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
|
||||||
|
@ -83,24 +76,22 @@ func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
name := "test-api-images-delete"
|
name := "test-api-images-delete"
|
||||||
out, err := buildImage(name, "FROM hello-world\nENV FOO bar", false)
|
out, err := buildImage(name, "FROM hello-world\nENV FOO bar", false)
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil)
|
||||||
c.Fatal(err)
|
|
||||||
}
|
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
|
|
||||||
dockerCmd(c, "tag", name, "test:tag1")
|
dockerCmd(c, "tag", name, "test:tag1")
|
||||||
|
|
||||||
status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusConflict)
|
c.Assert(status, checker.Equals, http.StatusConflict)
|
||||||
|
|
||||||
status, _, err = sockRequest("DELETE", "/images/test:noexist", nil)
|
status, _, err = sockRequest("DELETE", "/images/test:noexist", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusNotFound) //Status Codes:404 – no such image
|
c.Assert(status, checker.Equals, http.StatusNotFound) //Status Codes:404 – no such image
|
||||||
|
|
||||||
status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
c.Assert(status, checker.Equals, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
||||||
|
@ -108,21 +99,20 @@ func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
name := "test-api-images-history"
|
name := "test-api-images-history"
|
||||||
out, err := buildImage(name, "FROM hello-world\nENV FOO bar", false)
|
out, err := buildImage(name, "FROM hello-world\nENV FOO bar", false)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
id := strings.TrimSpace(out)
|
id := strings.TrimSpace(out)
|
||||||
|
|
||||||
status, body, err := sockRequest("GET", "/images/"+id+"/history", nil)
|
status, body, err := sockRequest("GET", "/images/"+id+"/history", nil)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
c.Assert(status, check.Equals, http.StatusOK)
|
c.Assert(status, checker.Equals, http.StatusOK)
|
||||||
|
|
||||||
var historydata []types.ImageHistory
|
var historydata []types.ImageHistory
|
||||||
if err = json.Unmarshal(body, &historydata); err != nil {
|
err = json.Unmarshal(body, &historydata)
|
||||||
c.Fatalf("Error on unmarshal: %s", err)
|
c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))
|
||||||
}
|
|
||||||
|
|
||||||
c.Assert(len(historydata), check.Not(check.Equals), 0)
|
c.Assert(historydata, checker.Not(checker.HasLen), 0)
|
||||||
c.Assert(historydata[0].Tags[0], check.Equals, "test-api-images-history:latest")
|
c.Assert(historydata[0].Tags[0], checker.Equals, "test-api-images-history:latest")
|
||||||
}
|
}
|
||||||
|
|
||||||
// #14846
|
// #14846
|
||||||
|
@ -132,6 +122,6 @@ func (s *DockerSuite) TestApiImagesSearchJSONContentType(c *check.C) {
|
||||||
res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
b.Close()
|
b.Close()
|
||||||
c.Assert(res.StatusCode, check.Equals, http.StatusOK)
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
||||||
c.Assert(res.Header.Get("Content-Type"), check.Equals, "application/json")
|
c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue