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-13 23:02:29 -04:00
|
|
|
"strings"
|
2015-04-07 21:57:54 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLegacyImages(t *testing.T) {
|
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 {
|
|
|
|
t.Fatalf("Error on GET: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
images := []types.LegacyImage{}
|
|
|
|
if err = json.Unmarshal(body, &images); err != nil {
|
|
|
|
t.Fatalf("Error on unmarshal: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) == 0 || images[0].Tag == "" || images[0].Repository == "" {
|
|
|
|
t.Fatalf("Bad data: %q", images)
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("images - checking legacy json")
|
|
|
|
}
|
2015-04-10 17:51:40 -04:00
|
|
|
|
|
|
|
func TestApiImagesFilter(t *testing.T) {
|
|
|
|
name := "utest:tag1"
|
|
|
|
name2 := "utest/docker:tag2"
|
|
|
|
name3 := "utest:5000/docker:tag3"
|
|
|
|
defer deleteImages(name, name2, name3)
|
|
|
|
dockerCmd(t, "tag", "busybox", name)
|
|
|
|
dockerCmd(t, "tag", "busybox", name2)
|
|
|
|
dockerCmd(t, "tag", "busybox", name3)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
var images []image
|
|
|
|
if err := json.Unmarshal(b, &images); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return images
|
|
|
|
}
|
|
|
|
|
|
|
|
errMsg := "incorrect number of matches returned"
|
|
|
|
if images := getImages("utest*/*"); len(images[0].RepoTags) != 2 {
|
|
|
|
t.Fatal(errMsg)
|
|
|
|
}
|
|
|
|
if images := getImages("utest"); len(images[0].RepoTags) != 1 {
|
|
|
|
t.Fatal(errMsg)
|
|
|
|
}
|
|
|
|
if images := getImages("utest*"); len(images[0].RepoTags) != 1 {
|
|
|
|
t.Fatal(errMsg)
|
|
|
|
}
|
|
|
|
if images := getImages("*5000*/*"); len(images[0].RepoTags) != 1 {
|
|
|
|
t.Fatal(errMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("images - filter param is applied")
|
|
|
|
}
|
2015-04-13 23:02:29 -04:00
|
|
|
|
|
|
|
func TestApiImagesSaveAndLoad(t *testing.T) {
|
|
|
|
out, err := buildImage("saveandload", "FROM hello-world\nENV FOO bar", false)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
id := strings.TrimSpace(out)
|
|
|
|
defer deleteImages("saveandload")
|
|
|
|
|
|
|
|
_, body, err := sockRequestRaw("GET", "/images/"+id+"/get", nil, "")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer body.Close()
|
|
|
|
|
|
|
|
dockerCmd(t, "rmi", id)
|
|
|
|
|
|
|
|
_, loadBody, err := sockRequestRaw("POST", "/images/load", body, "application/x-tar")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer loadBody.Close()
|
|
|
|
|
|
|
|
out, _, _ = dockerCmd(t, "inspect", "--format='{{ .Id }}'", id)
|
|
|
|
if strings.TrimSpace(out) != id {
|
|
|
|
t.Fatal("load did not work properly")
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("images API - save and load")
|
|
|
|
}
|