2015-04-08 01:57:54 +00:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2015-04-20 21:03:56 +00:00
|
|
|
|
"net/http"
|
2015-04-10 21:51:40 +00:00
|
|
|
|
"net/url"
|
2015-04-14 03:02:29 +00:00
|
|
|
|
"strings"
|
2015-04-08 01:57:54 +00:00
|
|
|
|
|
2015-11-18 13:06:29 +00:00
|
|
|
|
"github.com/docker/docker/pkg/integration/checker"
|
2016-01-05 00:05:26 +00:00
|
|
|
|
"github.com/docker/engine-api/types"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
"github.com/go-check/check"
|
2015-04-08 01:57:54 +00:00
|
|
|
|
)
|
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
|
func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
2015-04-10 21:51:40 +00:00
|
|
|
|
name := "utest:tag1"
|
|
|
|
|
name2 := "utest/docker:tag2"
|
|
|
|
|
name3 := "utest:5000/docker:tag3"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
for _, n := range []string{name, name2, name3} {
|
2015-07-14 06:35:36 +00:00
|
|
|
|
dockerCmd(c, "tag", "busybox", n)
|
2015-04-18 16:46:47 +00:00
|
|
|
|
}
|
2015-04-29 11:56:45 +00:00
|
|
|
|
type image types.Image
|
2015-04-10 21:51:40 +00:00
|
|
|
|
getImages := func(filter string) []image {
|
|
|
|
|
v := url.Values{}
|
|
|
|
|
v.Set("filter", filter)
|
2015-04-20 21:03:56 +00:00
|
|
|
|
status, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-04-20 21:03:56 +00:00
|
|
|
|
|
2015-04-10 21:51:40 +00:00
|
|
|
|
var images []image
|
2015-11-18 13:06:29 +00:00
|
|
|
|
err = json.Unmarshal(b, &images)
|
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-10 21:51:40 +00:00
|
|
|
|
|
|
|
|
|
return images
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 13:06:29 +00:00
|
|
|
|
//incorrect number of matches returned
|
|
|
|
|
images := getImages("utest*/*")
|
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 2)
|
|
|
|
|
|
|
|
|
|
images = getImages("utest")
|
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
|
|
|
|
|
|
|
|
|
images = getImages("utest*")
|
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
|
|
|
|
|
|
|
|
|
images = getImages("*5000*/*")
|
|
|
|
|
c.Assert(images[0].RepoTags, checker.HasLen, 1)
|
2015-04-10 21:51:40 +00:00
|
|
|
|
}
|
2015-04-14 03:02:29 +00:00
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
|
func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
2016-01-23 05:13:38 +00:00
|
|
|
|
// TODO Windows to Windows CI: Investigate further why this test fails.
|
2015-04-18 16:46:47 +00:00
|
|
|
|
testRequires(c, Network)
|
2015-08-28 17:36:42 +00:00
|
|
|
|
testRequires(c, DaemonIsLinux)
|
2016-01-23 05:13:38 +00:00
|
|
|
|
out, err := buildImage("saveandload", "FROM busybox\nENV FOO bar", false)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
2015-04-27 16:33:08 +00:00
|
|
|
|
res, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
defer body.Close()
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
|
dockerCmd(c, "rmi", id)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
|
2015-04-27 16:33:08 +00:00
|
|
|
|
res, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
defer loadBody.Close()
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
2015-04-14 03:02:29 +00:00
|
|
|
|
|
2016-01-28 14:19:25 +00:00
|
|
|
|
inspectOut := inspectField(c, id, "Id")
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(strings.TrimSpace(string(inspectOut)), checker.Equals, id, check.Commentf("load did not work properly"))
|
2015-04-14 03:02:29 +00:00
|
|
|
|
}
|
2015-04-29 11:56:45 +00:00
|
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiImagesDelete(c *check.C) {
|
2016-01-23 05:13:38 +00:00
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
}
|
2015-04-29 11:56:45 +00:00
|
|
|
|
name := "test-api-images-delete"
|
2016-01-23 05:13:38 +00:00
|
|
|
|
out, err := buildImage(name, "FROM busybox\nENV FOO bar", false)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-04-29 11:56:45 +00:00
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
2015-07-14 06:35:36 +00:00
|
|
|
|
dockerCmd(c, "tag", name, "test:tag1")
|
2015-04-29 11:56:45 +00:00
|
|
|
|
|
|
|
|
|
status, _, err := sockRequest("DELETE", "/images/"+id, nil)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusConflict)
|
2015-04-29 11:56:45 +00:00
|
|
|
|
|
2015-05-04 07:39:40 +00:00
|
|
|
|
status, _, err = sockRequest("DELETE", "/images/test:noexist", nil)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusNotFound) //Status Codes:404 – no such image
|
2015-05-04 07:39:40 +00:00
|
|
|
|
|
2015-04-29 11:56:45 +00:00
|
|
|
|
status, _, err = sockRequest("DELETE", "/images/test:tag1", nil)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-04-29 11:56:45 +00:00
|
|
|
|
}
|
2015-05-02 05:30:35 +00:00
|
|
|
|
|
|
|
|
|
func (s *DockerSuite) TestApiImagesHistory(c *check.C) {
|
2016-01-23 05:13:38 +00:00
|
|
|
|
if daemonPlatform != "windows" {
|
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
}
|
2015-05-02 05:30:35 +00:00
|
|
|
|
name := "test-api-images-history"
|
2016-01-23 05:13:38 +00:00
|
|
|
|
out, err := buildImage(name, "FROM busybox\nENV FOO bar", false)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
2015-05-02 05:30:35 +00:00
|
|
|
|
|
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
|
|
|
|
|
|
status, body, err := sockRequest("GET", "/images/"+id+"/history", nil)
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
c.Assert(status, checker.Equals, http.StatusOK)
|
2015-05-02 05:30:35 +00:00
|
|
|
|
|
|
|
|
|
var historydata []types.ImageHistory
|
2015-11-18 13:06:29 +00:00
|
|
|
|
err = json.Unmarshal(body, &historydata)
|
|
|
|
|
c.Assert(err, checker.IsNil, check.Commentf("Error on unmarshal"))
|
2015-05-02 05:30:35 +00:00
|
|
|
|
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(historydata, checker.Not(checker.HasLen), 0)
|
|
|
|
|
c.Assert(historydata[0].Tags[0], checker.Equals, "test-api-images-history:latest")
|
2015-05-02 05:30:35 +00:00
|
|
|
|
}
|
2015-07-22 09:07:41 +00:00
|
|
|
|
|
|
|
|
|
// #14846
|
|
|
|
|
func (s *DockerSuite) TestApiImagesSearchJSONContentType(c *check.C) {
|
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
|
|
|
|
|
res, b, err := sockRequestRaw("GET", "/images/search?term=test", nil, "application/json")
|
|
|
|
|
c.Assert(err, check.IsNil)
|
2015-07-23 11:24:14 +00:00
|
|
|
|
b.Close()
|
2015-11-18 13:06:29 +00:00
|
|
|
|
c.Assert(res.StatusCode, checker.Equals, http.StatusOK)
|
|
|
|
|
c.Assert(res.Header.Get("Content-Type"), checker.Equals, "application/json")
|
2015-07-22 09:07:41 +00:00
|
|
|
|
}
|