|
@@ -2,6 +2,9 @@ package main
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "io/ioutil"
|
|
|
|
+ "os"
|
|
|
|
+ "path/filepath"
|
|
"reflect"
|
|
"reflect"
|
|
"sort"
|
|
"sort"
|
|
"strings"
|
|
"strings"
|
|
@@ -48,17 +51,17 @@ func (s *DockerSuite) TestImagesOrderedByCreationDate(c *check.C) {
|
|
testRequires(c, DaemonIsLinux)
|
|
testRequires(c, DaemonIsLinux)
|
|
id1, err := buildImage("order:test_a",
|
|
id1, err := buildImage("order:test_a",
|
|
`FROM scratch
|
|
`FROM scratch
|
|
- MAINTAINER dockerio1`, true)
|
|
|
|
|
|
+ MAINTAINER dockerio1`, true)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(err, checker.IsNil)
|
|
time.Sleep(1 * time.Second)
|
|
time.Sleep(1 * time.Second)
|
|
id2, err := buildImage("order:test_c",
|
|
id2, err := buildImage("order:test_c",
|
|
`FROM scratch
|
|
`FROM scratch
|
|
- MAINTAINER dockerio2`, true)
|
|
|
|
|
|
+ MAINTAINER dockerio2`, true)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(err, checker.IsNil)
|
|
time.Sleep(1 * time.Second)
|
|
time.Sleep(1 * time.Second)
|
|
id3, err := buildImage("order:test_b",
|
|
id3, err := buildImage("order:test_b",
|
|
`FROM scratch
|
|
`FROM scratch
|
|
- MAINTAINER dockerio3`, true)
|
|
|
|
|
|
+ MAINTAINER dockerio3`, true)
|
|
c.Assert(err, checker.IsNil)
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
|
|
out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
|
|
out, _ := dockerCmd(c, "images", "-q", "--no-trunc")
|
|
@@ -81,17 +84,17 @@ func (s *DockerSuite) TestImagesFilterLabelMatch(c *check.C) {
|
|
imageName3 := "images_filter_test3"
|
|
imageName3 := "images_filter_test3"
|
|
image1ID, err := buildImage(imageName1,
|
|
image1ID, err := buildImage(imageName1,
|
|
`FROM scratch
|
|
`FROM scratch
|
|
- LABEL match me`, true)
|
|
|
|
|
|
+ LABEL match me`, true)
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
image2ID, err := buildImage(imageName2,
|
|
image2ID, err := buildImage(imageName2,
|
|
`FROM scratch
|
|
`FROM scratch
|
|
- LABEL match="me too"`, true)
|
|
|
|
|
|
+ LABEL match="me too"`, true)
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
image3ID, err := buildImage(imageName3,
|
|
image3ID, err := buildImage(imageName3,
|
|
`FROM scratch
|
|
`FROM scratch
|
|
- LABEL nomatch me`, true)
|
|
|
|
|
|
+ LABEL nomatch me`, true)
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
|
|
out, _ := dockerCmd(c, "images", "--no-trunc", "-q", "-f", "label=match")
|
|
@@ -123,9 +126,9 @@ func (s *DockerSuite) TestImagesFilterSpaceTrimCase(c *check.C) {
|
|
imageName := "images_filter_test"
|
|
imageName := "images_filter_test"
|
|
buildImage(imageName,
|
|
buildImage(imageName,
|
|
`FROM scratch
|
|
`FROM scratch
|
|
- RUN touch /test/foo
|
|
|
|
- RUN touch /test/bar
|
|
|
|
- RUN touch /test/baz`, true)
|
|
|
|
|
|
+ RUN touch /test/foo
|
|
|
|
+ RUN touch /test/bar
|
|
|
|
+ RUN touch /test/baz`, true)
|
|
|
|
|
|
filters := []string{
|
|
filters := []string{
|
|
"dangling=true",
|
|
"dangling=true",
|
|
@@ -233,3 +236,46 @@ func (s *DockerSuite) TestImagesFilterNameWithPort(c *check.C) {
|
|
out, _ = dockerCmd(c, "images", tag+":no-such-tag")
|
|
out, _ = dockerCmd(c, "images", tag+":no-such-tag")
|
|
c.Assert(out, checker.Not(checker.Contains), tag)
|
|
c.Assert(out, checker.Not(checker.Contains), tag)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (s *DockerSuite) TestImagesFormat(c *check.C) {
|
|
|
|
+ // testRequires(c, DaemonIsLinux)
|
|
|
|
+ tag := "myimage"
|
|
|
|
+ dockerCmd(c, "tag", "busybox", tag+":v1")
|
|
|
|
+ dockerCmd(c, "tag", "busybox", tag+":v2")
|
|
|
|
+
|
|
|
|
+ out, _ := dockerCmd(c, "images", "--format", "{{.Repository}}", tag)
|
|
|
|
+ lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
|
|
|
+
|
|
|
|
+ expected := []string{"myimage", "myimage"}
|
|
|
|
+ var names []string
|
|
|
|
+ for _, l := range lines {
|
|
|
|
+ names = append(names, l)
|
|
|
|
+ }
|
|
|
|
+ c.Assert(expected, checker.DeepEquals, names, check.Commentf("Expected array with truncated names: %v, got: %v", expected, names))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// ImagesDefaultFormatAndQuiet
|
|
|
|
+func (s *DockerSuite) TestImagesFormatDefaultFormat(c *check.C) {
|
|
|
|
+ testRequires(c, DaemonIsLinux)
|
|
|
|
+
|
|
|
|
+ // create container 1
|
|
|
|
+ out, _ := dockerCmd(c, "run", "-d", "busybox", "true")
|
|
|
|
+ containerID1 := strings.TrimSpace(out)
|
|
|
|
+
|
|
|
|
+ // tag as foobox
|
|
|
|
+ out, _ = dockerCmd(c, "commit", containerID1, "myimage")
|
|
|
|
+ imageID := stringid.TruncateID(strings.TrimSpace(out))
|
|
|
|
+
|
|
|
|
+ config := `{
|
|
|
|
+ "imagesFormat": "{{ .ID }} default"
|
|
|
|
+}`
|
|
|
|
+ d, err := ioutil.TempDir("", "integration-cli-")
|
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
+ defer os.RemoveAll(d)
|
|
|
|
+
|
|
|
|
+ err = ioutil.WriteFile(filepath.Join(d, "config.json"), []byte(config), 0644)
|
|
|
|
+ c.Assert(err, checker.IsNil)
|
|
|
|
+
|
|
|
|
+ out, _ = dockerCmd(c, "--config", d, "images", "-q", "myimage")
|
|
|
|
+ c.Assert(out, checker.Equals, imageID+"\n", check.Commentf("Expected to print only the image id, got %v\n", out))
|
|
|
|
+}
|