2015-04-07 21:57:54 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2015-04-10 17:51:40 -04:00
|
|
|
"net/url"
|
2015-04-18 12:46:47 -04:00
|
|
|
"os/exec"
|
2015-04-13 23:02:29 -04:00
|
|
|
"strings"
|
2015-04-07 21:57:54 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2015-04-07 21:57:54 -04:00
|
|
|
)
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLegacyImages(c *check.C) {
|
2015-04-11 17:49:14 -04:00
|
|
|
_, body, err := sockRequest("GET", "/v1.6/images/json", nil)
|
2015-04-07 21:57:54 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error on GET: %s", err)
|
2015-04-07 21:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
images := []types.LegacyImage{}
|
|
|
|
if err = json.Unmarshal(body, &images); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error on unmarshal: %s", err)
|
2015-04-07 21:57:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) == 0 || images[0].Tag == "" || images[0].Repository == "" {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Bad data: %q", images)
|
2015-04-07 21:57:54 -04:00
|
|
|
}
|
|
|
|
}
|
2015-04-10 17:51:40 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestApiImagesFilter(c *check.C) {
|
2015-04-10 17:51:40 -04:00
|
|
|
name := "utest:tag1"
|
|
|
|
name2 := "utest/docker:tag2"
|
|
|
|
name3 := "utest:5000/docker:tag3"
|
|
|
|
defer deleteImages(name, name2, name3)
|
2015-04-18 12:46:47 -04:00
|
|
|
for _, n := range []string{name, name2, name3} {
|
|
|
|
if out, err := exec.Command(dockerBinary, "tag", "busybox", n).CombinedOutput(); err != nil {
|
|
|
|
c.Fatal(err, out)
|
|
|
|
}
|
|
|
|
}
|
2015-04-10 17:51:40 -04:00
|
|
|
type image struct{ RepoTags []string }
|
|
|
|
getImages := func(filter string) []image {
|
|
|
|
v := url.Values{}
|
|
|
|
v.Set("filter", filter)
|
|
|
|
_, b, err := sockRequest("GET", "/images/json?"+v.Encode(), nil)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-04-10 17:51:40 -04:00
|
|
|
}
|
|
|
|
var images []image
|
|
|
|
if err := json.Unmarshal(b, &images); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-04-10 17:51:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return images
|
|
|
|
}
|
|
|
|
|
|
|
|
errMsg := "incorrect number of matches returned"
|
|
|
|
if images := getImages("utest*/*"); len(images[0].RepoTags) != 2 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(errMsg)
|
2015-04-10 17:51:40 -04:00
|
|
|
}
|
|
|
|
if images := getImages("utest"); len(images[0].RepoTags) != 1 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(errMsg)
|
2015-04-10 17:51:40 -04:00
|
|
|
}
|
|
|
|
if images := getImages("utest*"); len(images[0].RepoTags) != 1 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(errMsg)
|
2015-04-10 17:51:40 -04:00
|
|
|
}
|
|
|
|
if images := getImages("*5000*/*"); len(images[0].RepoTags) != 1 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(errMsg)
|
2015-04-10 17:51:40 -04:00
|
|
|
}
|
|
|
|
}
|
2015-04-13 23:02:29 -04:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestApiImagesSaveAndLoad(c *check.C) {
|
|
|
|
testRequires(c, Network)
|
2015-04-13 23:02:29 -04:00
|
|
|
out, err := buildImage("saveandload", "FROM hello-world\nENV FOO bar", false)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-04-13 23:02:29 -04:00
|
|
|
}
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
defer deleteImages("saveandload")
|
|
|
|
|
|
|
|
_, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-04-13 23:02:29 -04:00
|
|
|
}
|
|
|
|
defer body.Close()
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
if out, err := exec.Command(dockerBinary, "rmi", id).CombinedOutput(); err != nil {
|
|
|
|
c.Fatal(err, out)
|
|
|
|
}
|
2015-04-13 23:02:29 -04:00
|
|
|
|
|
|
|
_, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(err)
|
2015-04-13 23:02:29 -04:00
|
|
|
}
|
|
|
|
defer loadBody.Close()
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
inspectOut, err := exec.Command(dockerBinary, "inspect", "--format='{{ .Id }}'", id).CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
c.Fatal(err, inspectOut)
|
|
|
|
}
|
|
|
|
if strings.TrimSpace(string(inspectOut)) != id {
|
|
|
|
c.Fatal("load did not work properly")
|
2015-04-13 23:02:29 -04:00
|
|
|
}
|
|
|
|
}
|