"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "components/engine/integration-cli/docker_cli_images_test.go" between
docker-ce-19.03.2.tar.gz and docker-ce-19.03.3.tar.gz

About: Docker CE is a project to pack, ship and run any application as a lightweight container. Docker containers can run anywhere, on a laptop or at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more. Community edition.

docker_cli_images_test.go  (docker-ce-19.03.2):docker_cli_images_test.go  (docker-ce-19.03.3)
package main package main
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"sort" "sort"
"strings" "strings"
"testing"
"time" "time"
"github.com/docker/docker/integration-cli/checker"
"github.com/docker/docker/integration-cli/cli/build" "github.com/docker/docker/integration-cli/cli/build"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/go-check/check"
"gotest.tools/assert" "gotest.tools/assert"
is "gotest.tools/assert/cmp" is "gotest.tools/assert/cmp"
"gotest.tools/icmd" "gotest.tools/icmd"
) )
func (s *DockerSuite) TestImagesEnsureImageIsListed(c *check.C) { func (s *DockerSuite) TestImagesEnsureImageIsListed(c *testing.T) {
imagesOut, _ := dockerCmd(c, "images") imagesOut, _ := dockerCmd(c, "images")
c.Assert(imagesOut, checker.Contains, "busybox") assert.Assert(c, strings.Contains(imagesOut, "busybox"))
} }
func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *check.C) { func (s *DockerSuite) TestImagesEnsureImageWithTagIsListed(c *testing.T) {
name := "imagewithtag" name := "imagewithtag"
dockerCmd(c, "tag", "busybox", name+":v1") dockerCmd(c, "tag", "busybox", name+":v1")
dockerCmd(c, "tag", "busybox", name+":v1v1") dockerCmd(c, "tag", "busybox", name+":v1v1")
dockerCmd(c, "tag", "busybox", name+":v2") dockerCmd(c, "tag", "busybox", name+":v2")
imagesOut, _ := dockerCmd(c, "images", name+":v1") imagesOut, _ := dockerCmd(c, "images", name+":v1")
c.Assert(imagesOut, checker.Contains, name) assert.Assert(c, strings.Contains(imagesOut, name))
c.Assert(imagesOut, checker.Contains, "v1") assert.Assert(c, strings.Contains(imagesOut, "v1"))
c.Assert(imagesOut, checker.Not(checker.Contains), "v2") assert.Assert(c, !strings.Contains(imagesOut, "v2"))
c.Assert(imagesOut, checker.Not(checker.Contains), "v1v1") assert.Assert(c, !strings.Contains(imagesOut, "v1v1"))
imagesOut, _ = dockerCmd(c, "images", name) imagesOut, _ = dockerCmd(c, "images", name)
c.Assert(imagesOut, checker.Contains, name) assert.Assert(c, strings.Contains(imagesOut, name))
c.Assert(imagesOut, checker.Contains, "v1") assert.Assert(c, strings.Contains(imagesOut, "v1"))
c.Assert(imagesOut, checker.Contains, "v1v1") assert.Assert(c, strings.Contains(imagesOut, "v1v1"))
c.Assert(imagesOut, checker.Contains, "v2") assert.Assert(c, strings.Contains(imagesOut, "v2"))
} }
func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *check.C) { func (s *DockerSuite) TestImagesEnsureImageWithBadTagIsNotListed(c *testing.T) {
imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent") imagesOut, _ := dockerCmd(c, "images", "busybox:nonexistent")
c.Assert(imagesOut, checker.Not(checker.Contains), "busybox") assert.Assert(c, !strings.Contains(imagesOut, "busybox"))
} }
func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) { func (s *DockerSuite) TestImagesOrderedByCreationDate(c *testing.T) {
buildImageSuccessfully(c, "order:test_a", build.WithDockerfile(`FROM busy box buildImageSuccessfully(c, "order:test_a", build.WithDockerfile(`FROM busy box
MAINTAINER dockerio1`)) MAINTAINER dockerio1`))
id1 := getIDByName(c, "order:test_a") id1 := getIDByName(c, "order:test_a")
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
buildImageSuccessfully(c, "order:test_c", build.WithDockerfile(`FROM busy box buildImageSuccessfully(c, "order:test_c", build.WithDockerfile(`FROM busy box
MAINTAINER dockerio2`)) MAINTAINER dockerio2`))
id2 := getIDByName(c, "order:test_c") id2 := getIDByName(c, "order:test_c")
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
buildImageSuccessfully(c, "order:test_b", build.WithDockerfile(`FROM busy box buildImageSuccessfully(c, "order:test_b", build.WithDockerfile(`FROM busy box
MAINTAINER dockerio3`)) MAINTAINER dockerio3`))
id3 := getIDByName(c, "order:test_b") id3 := getIDByName(c, "order:test_b")
out, _ := dockerCmd(c, "images", "-q", "--no-trunc") out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
imgs := strings.Split(out, "\n") imgs := strings.Split(out, "\n")
c.Assert(imgs[0], checker.Equals, id3, check.Commentf("First image must b assert.Equal(c, imgs[0], id3, fmt.Sprintf("First image must be %s, got %s
e %s, got %s", id3, imgs[0])) ", id3, imgs[0]))
c.Assert(imgs[1], checker.Equals, id2, check.Commentf("First image must b assert.Equal(c, imgs[1], id2, fmt.Sprintf("First image must be %s, got %s
e %s, got %s", id2, imgs[1])) ", id2, imgs[1]))
c.Assert(imgs[2], checker.Equals, id1, check.Commentf("First image must b assert.Equal(c, imgs[2], id1, fmt.Sprintf("First image must be %s, got %s
e %s, got %s", id1, imgs[2])) ", id1, imgs[2]))
} }
func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *check.C) { func (s *DockerSuite) TestImagesErrorWithInvalidFilterNameTest(c *testing.T) {
out, _, err := dockerCmdWithError("images", "-f", "FOO=123") out, _, err := dockerCmdWithError("images", "-f", "FOO=123")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Invalid filter") assert.Assert(c, strings.Contains(out, "Invalid filter"))
} }
func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) { func (s *DockerSuite) TestImagesFilterLabelMatch(c *testing.T) {
imageName1 := "images_filter_test1" imageName1 := "images_filter_test1"
imageName2 := "images_filter_test2" imageName2 := "images_filter_test2"
imageName3 := "images_filter_test3" imageName3 := "images_filter_test3"
buildImageSuccessfully(c, imageName1, build.WithDockerfile(`FROM busybox buildImageSuccessfully(c, imageName1, build.WithDockerfile(`FROM busybox
LABEL match me`)) LABEL match me`))
image1ID := getIDByName(c, imageName1) image1ID := getIDByName(c, imageName1)
buildImageSuccessfully(c, imageName2, build.WithDockerfile(`FROM busybox buildImageSuccessfully(c, imageName2, build.WithDockerfile(`FROM busybox
LABEL match="me too"`)) LABEL match="me too"`))
image2ID := getIDByName(c, imageName2) image2ID := getIDByName(c, imageName2)
buildImageSuccessfully(c, imageName3, build.WithDockerfile(`FROM busybox buildImageSuccessfully(c, imageName3, build.WithDockerfile(`FROM busybox
LABEL nomatch me`)) LABEL nomatch me`))
image3ID := getIDByName(c, imageName3) image3ID := getIDByName(c, imageName3)
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match") out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
out = strings.TrimSpace(out) out = strings.TrimSpace(out)
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image1 assert.Assert(c, is.Regexp(fmt.Sprintf("^[\\s\\w:]*%s[\\s\\w:]*$", image1
ID)) ID), out))
c.Assert(out, check.Matches, fmt.Sprintf("[\\s\\w:]*%s[\\s\\w:]*", image2
ID)) assert.Assert(c, is.Regexp(fmt.Sprintf("^[\\s\\w:]*%s[\\s\\w:]*$", image2
c.Assert(out, check.Not(check.Matches), fmt.Sprintf("[\\s\\w:]*%s[\\s\\w: ID), out))
]*", image3ID))
assert.Assert(c, !is.Regexp(fmt.Sprintf("^[\\s\\w:]*%s[\\s\\w:]*$", image
3ID), out)().Success())
out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too") out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match=me too")
out = strings.TrimSpace(out) out = strings.TrimSpace(out)
assert.Equal(c, out, image2ID) assert.Equal(c, out, image2ID)
} }
// Regression : #15659 // Regression : #15659
func (s *DockerSuite) TestCommitWithFilterLabel(c *check.C) { func (s *DockerSuite) TestCommitWithFilterLabel(c *testing.T) {
// Create a container // Create a container
dockerCmd(c, "run", "--name", "bar", "busybox", "/bin/sh") dockerCmd(c, "run", "--name", "bar", "busybox", "/bin/sh")
// Commit with labels "using changes" // Commit with labels "using changes"
out, _ := dockerCmd(c, "commit", "-c", "LABEL foo.version=1.0.0-1", "-c", "LABEL foo.name=bar", "-c", "LABEL foo.author=starlord", "bar", "bar:1.0.0-1") out, _ := dockerCmd(c, "commit", "-c", "LABEL foo.version=1.0.0-1", "-c", "LABEL foo.name=bar", "-c", "LABEL foo.author=starlord", "bar", "bar:1.0.0-1")
imageID := strings.TrimSpace(out) imageID := strings.TrimSpace(out)
out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=foo.vers ion=1.0.0-1") out, _ = dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=foo.vers ion=1.0.0-1")
out = strings.TrimSpace(out) out = strings.TrimSpace(out)
assert.Equal(c, out, imageID) assert.Equal(c, out, imageID)
} }
func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *check.C) { func (s *DockerSuite) TestImagesFilterSinceAndBefore(c *testing.T) {
buildImageSuccessfully(c, "image:1", build.WithDockerfile(`FROM `+minimal BaseImage()+` buildImageSuccessfully(c, "image:1", build.WithDockerfile(`FROM `+minimal BaseImage()+`
LABEL number=1`)) LABEL number=1`))
imageID1 := getIDByName(c, "image:1") imageID1 := getIDByName(c, "image:1")
buildImageSuccessfully(c, "image:2", build.WithDockerfile(`FROM `+minimal BaseImage()+` buildImageSuccessfully(c, "image:2", build.WithDockerfile(`FROM `+minimal BaseImage()+`
LABEL number=2`)) LABEL number=2`))
imageID2 := getIDByName(c, "image:2") imageID2 := getIDByName(c, "image:2")
buildImageSuccessfully(c, "image:3", build.WithDockerfile(`FROM `+minimal BaseImage()+` buildImageSuccessfully(c, "image:3", build.WithDockerfile(`FROM `+minimal BaseImage()+`
LABEL number=3`)) LABEL number=3`))
imageID3 := getIDByName(c, "image:3") imageID3 := getIDByName(c, "image:3")
expected := []string{imageID3, imageID2} expected := []string{imageID3, imageID2}
out, _ := dockerCmd(c, "images", "-f", "since=image:1", "image") out, _ := dockerCmd(c, "images", "-f", "since=image:1", "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, o ut)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "since="+imageID1, "image") out, _ = dockerCmd(c, "images", "-f", "since="+imageID1, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, o ut)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
expected = []string{imageID3} expected = []string{imageID3}
out, _ = dockerCmd(c, "images", "-f", "since=image:2", "image") out, _ = dockerCmd(c, "images", "-f", "since=image:2", "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, o ut)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "since="+imageID2, "image") out, _ = dockerCmd(c, "images", "-f", "since="+imageID2, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, o ut)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("SINCE filter: Image list is not in the correct order: %v\n%s", expected, out))
expected = []string{imageID2, imageID1} expected = []string{imageID2, imageID1}
out, _ = dockerCmd(c, "images", "-f", "before=image:3", "image") out, _ = dockerCmd(c, "images", "-f", "before=image:3", "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "before="+imageID3, "image") out, _ = dockerCmd(c, "images", "-f", "before="+imageID3, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
expected = []string{imageID1} expected = []string{imageID1}
out, _ = dockerCmd(c, "images", "-f", "before=image:2", "image") out, _ = dockerCmd(c, "images", "-f", "before=image:2", "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
out, _ = dockerCmd(c, "images", "-f", "before="+imageID2, "image") out, _ = dockerCmd(c, "images", "-f", "before="+imageID2, "image")
c.Assert(assertImageList(out, expected), checker.Equals, true, check.Comm entf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out)) assert.Equal(c, assertImageList(out, expected), true, fmt.Sprintf("BEFORE filter: Image list is not in the correct order: %v\n%s", expected, out))
} }
func assertImageList(out string, expected []string) bool { func assertImageList(out string, expected []string) bool {
lines := strings.Split(strings.Trim(out, "\n "), "\n") lines := strings.Split(strings.Trim(out, "\n "), "\n")
if len(lines)-1 != len(expected) { if len(lines)-1 != len(expected) {
return false return false
} }
imageIDIndex := strings.Index(lines[0], "IMAGE ID") imageIDIndex := strings.Index(lines[0], "IMAGE ID")
skipping to change at line 187 skipping to change at line 187
} }
if !found { if !found {
return false return false
} }
} }
return true return true
} }
// FIXME(vdemeester) should be a unit test on `docker image ls` // FIXME(vdemeester) should be a unit test on `docker image ls`
func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) { func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *testing.T) {
imageName := "images_filter_test" imageName := "images_filter_test"
// Build a image and fail to build so that we have dangling images ? // Build a image and fail to build so that we have dangling images ?
buildImage(imageName, build.WithDockerfile(`FROM busybox buildImage(imageName, build.WithDockerfile(`FROM busybox
RUN touch /test/foo RUN touch /test/foo
RUN touch /test/bar RUN touch /test/bar
RUN touch /test/baz`)).Assert(c, icmd.Expected{ RUN touch /test/baz`)).Assert(c, icmd.Expected{
ExitCode: 1, ExitCode: 1,
}) })
filters := []string{ filters := []string{
skipping to change at line 227 skipping to change at line 227
for _, image := range errListing { for _, image := range errListing {
fmt.Print(image) fmt.Print(image)
} }
fmt.Print("") fmt.Print("")
} }
c.Fatalf("All output must be the same") c.Fatalf("All output must be the same")
} }
} }
} }
func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *check.C) { func (s *DockerSuite) TestImagesEnsureDanglingImageOnlyListedOnce(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// create container 1 // create container 1
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
containerID1 := strings.TrimSpace(out) containerID1 := strings.TrimSpace(out)
// tag as foobox // tag as foobox
out, _ = dockerCmd(c, "commit", containerID1, "foobox") out, _ = dockerCmd(c, "commit", containerID1, "foobox")
imageID := stringid.TruncateID(strings.TrimSpace(out)) imageID := stringid.TruncateID(strings.TrimSpace(out))
// overwrite the tag, making the previous image dangling // overwrite the tag, making the previous image dangling
dockerCmd(c, "tag", "busybox", "foobox") dockerCmd(c, "tag", "busybox", "foobox")
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true") out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=true")
// Expect one dangling image // Expect one dangling image
c.Assert(strings.Count(out, imageID), checker.Equals, 1) assert.Equal(c, strings.Count(out, imageID), 1)
out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false") out, _ = dockerCmd(c, "images", "-q", "-f", "dangling=false")
//dangling=false would not include dangling images //dangling=false would not include dangling images
c.Assert(out, checker.Not(checker.Contains), imageID) assert.Assert(c, !strings.Contains(out, imageID))
out, _ = dockerCmd(c, "images") out, _ = dockerCmd(c, "images")
//docker images still include dangling images //docker images still include dangling images
c.Assert(out, checker.Contains, imageID) assert.Assert(c, strings.Contains(out, imageID))
} }
// FIXME(vdemeester) should be a unit test for `docker image ls` // FIXME(vdemeester) should be a unit test for `docker image ls`
func (s *DockerSuite) TestImagesWithIncorrectFilter(c *check.C) { func (s *DockerSuite) TestImagesWithIncorrectFilter(c *testing.T) {
out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid") out, _, err := dockerCmdWithError("images", "-f", "dangling=invalid")
assert.ErrorContains(c, err, "") assert.ErrorContains(c, err, "")
c.Assert(out, checker.Contains, "Invalid filter") assert.Assert(c, strings.Contains(out, "Invalid filter"))
} }
func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *check.C) { func (s *DockerSuite) TestImagesEnsureOnlyHeadsImagesShown(c *testing.T) {
dockerfile := ` dockerfile := `
FROM busybox FROM busybox
MAINTAINER docker MAINTAINER docker
ENV foo bar` ENV foo bar`
name := "scratch-image" name := "scratch-image"
result := buildImage(name, build.WithDockerfile(dockerfile)) result := buildImage(name, build.WithDockerfile(dockerfile))
result.Assert(c, icmd.Success) result.Assert(c, icmd.Success)
id := getIDByName(c, name) id := getIDByName(c, name)
// this is just the output of docker build // this is just the output of docker build
// we're interested in getting the image id of the MAINTAINER instruction // we're interested in getting the image id of the MAINTAINER instruction
// and that's located at output, line 5, from 7 to end // and that's located at output, line 5, from 7 to end
split := strings.Split(result.Combined(), "\n") split := strings.Split(result.Combined(), "\n")
intermediate := strings.TrimSpace(split[5][7:]) intermediate := strings.TrimSpace(split[5][7:])
out, _ := dockerCmd(c, "images") out, _ := dockerCmd(c, "images")
// images shouldn't show non-heads images // images shouldn't show non-heads images
c.Assert(out, checker.Not(checker.Contains), intermediate) assert.Assert(c, !strings.Contains(out, intermediate))
// images should contain final built images // images should contain final built images
c.Assert(out, checker.Contains, stringid.TruncateID(id)) assert.Assert(c, strings.Contains(out, stringid.TruncateID(id)))
} }
func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *check.C) { func (s *DockerSuite) TestImagesEnsureImagesFromScratchShown(c *testing.T) {
testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch testRequires(c, DaemonIsLinux) // Windows does not support FROM scratch
dockerfile := ` dockerfile := `
FROM scratch FROM scratch
MAINTAINER docker` MAINTAINER docker`
name := "scratch-image" name := "scratch-image"
buildImageSuccessfully(c, name, build.WithDockerfile(dockerfile)) buildImageSuccessfully(c, name, build.WithDockerfile(dockerfile))
id := getIDByName(c, name) id := getIDByName(c, name)
out, _ := dockerCmd(c, "images") out, _ := dockerCmd(c, "images")
// images should contain images built from scratch // images should contain images built from scratch
c.Assert(out, checker.Contains, stringid.TruncateID(id)) assert.Assert(c, strings.Contains(out, stringid.TruncateID(id)))
} }
// For W2W - equivalent to TestImagesEnsureImagesFromScratchShown but Windows // For W2W - equivalent to TestImagesEnsureImagesFromScratchShown but Windows
// doesn't support from scratch // doesn't support from scratch
func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *check.C) { func (s *DockerSuite) TestImagesEnsureImagesFromBusyboxShown(c *testing.T) {
dockerfile := ` dockerfile := `
FROM busybox FROM busybox
MAINTAINER docker` MAINTAINER docker`
name := "busybox-image" name := "busybox-image"
buildImageSuccessfully(c, name, build.WithDockerfile(dockerfile)) buildImageSuccessfully(c, name, build.WithDockerfile(dockerfile))
id := getIDByName(c, name) id := getIDByName(c, name)
out, _ := dockerCmd(c, "images") out, _ := dockerCmd(c, "images")
// images should contain images built from busybox // images should contain images built from busybox
c.Assert(out, checker.Contains, stringid.TruncateID(id)) assert.Assert(c, strings.Contains(out, stringid.TruncateID(id)))
} }
// #18181 // #18181
func (s *DockerSuite) TestImagesFilterNameWithPort(c *check.C) { func (s *DockerSuite) TestImagesFilterNameWithPort(c *testing.T) {
tag := "a.b.c.d:5000/hello" tag := "a.b.c.d:5000/hello"
dockerCmd(c, "tag", "busybox", tag) dockerCmd(c, "tag", "busybox", tag)
out, _ := dockerCmd(c, "images", tag) out, _ := dockerCmd(c, "images", tag)
c.Assert(out, checker.Contains, tag) assert.Assert(c, strings.Contains(out, tag))
out, _ = dockerCmd(c, "images", tag+":latest") out, _ = dockerCmd(c, "images", tag+":latest")
c.Assert(out, checker.Contains, tag) assert.Assert(c, strings.Contains(out, tag))
out, _ = dockerCmd(c, "images", tag+":no-such-tag") out, _ = dockerCmd(c, "images", tag+":no-such-tag")
c.Assert(out, checker.Not(checker.Contains), tag) assert.Assert(c, !strings.Contains(out, tag))
} }
func (s *DockerSuite) TestImagesFormat(c *check.C) { func (s *DockerSuite) TestImagesFormat(c *testing.T) {
// testRequires(c, DaemonIsLinux) // testRequires(c, DaemonIsLinux)
tag := "myimage" tag := "myimage"
dockerCmd(c, "tag", "busybox", tag+":v1") dockerCmd(c, "tag", "busybox", tag+":v1")
dockerCmd(c, "tag", "busybox", tag+":v2") dockerCmd(c, "tag", "busybox", tag+":v2")
out, _ := dockerCmd(c, "images", "--format", "{{.Repository}}", tag) out, _ := dockerCmd(c, "images", "--format", "{{.Repository}}", tag)
lines := strings.Split(strings.TrimSpace(string(out)), "\n") lines := strings.Split(strings.TrimSpace(string(out)), "\n")
expected := []string{"myimage", "myimage"} expected := []string{"myimage", "myimage"}
var names []string var names []string
names = append(names, lines...) names = append(names, lines...)
assert.Assert(c, is.DeepEqual(names, expected), "Expected array with trun cated names: %v, got: %v", expected, names) assert.Assert(c, is.DeepEqual(names, expected), "Expected array with trun cated names: %v, got: %v", expected, names)
} }
// ImagesDefaultFormatAndQuiet // ImagesDefaultFormatAndQuiet
func (s *DockerSuite) TestImagesFormatDefaultFormat(c *check.C) { func (s *DockerSuite) TestImagesFormatDefaultFormat(c *testing.T) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
// create container 1 // create container 1
out, _ := dockerCmd(c, "run", "-d", "busybox", "true") out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
containerID1 := strings.TrimSpace(out) containerID1 := strings.TrimSpace(out)
// tag as foobox // tag as foobox
out, _ = dockerCmd(c, "commit", containerID1, "myimage") out, _ = dockerCmd(c, "commit", containerID1, "myimage")
imageID := stringid.TruncateID(strings.TrimSpace(out)) imageID := stringid.TruncateID(strings.TrimSpace(out))
 End of changes. 46 change blocks. 
66 lines changed or deleted 62 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)