diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | cmd/podman/images.go | 15 | ||||
-rw-r--r-- | libpod/image/image.go | 3 | ||||
-rw-r--r-- | pkg/network/files.go | 4 | ||||
-rw-r--r-- | test/e2e/images_test.go | 32 |
5 files changed, 43 insertions, 14 deletions
@@ -524,7 +524,10 @@ install.libseccomp.sudo: cmd/podman/varlink/iopodman.go: .gopathok cmd/podman/varlink/io.podman.varlink +ifeq ("$(shell uname -o)", "GNU/Linux") + # Only generate the varlink code on Linux (see issue #4814). GO111MODULE=off $(GO) generate ./cmd/podman/varlink/... +endif API.md: cmd/podman/varlink/io.podman.varlink $(GO) generate ./docs/... diff --git a/cmd/podman/images.go b/cmd/podman/images.go index 75cdd3465..115f30d9b 100644 --- a/cmd/podman/images.go +++ b/cmd/podman/images.go @@ -159,6 +159,21 @@ func imagesCmd(c *cliconfig.ImagesValues) error { filters = append(filters, fmt.Sprintf("reference=%s", image)) } + var sortValues = map[string]bool{ + "created": true, + "id": true, + "repository": true, + "size": true, + "tag": true, + } + if !sortValues[c.Sort] { + keys := make([]string, 0, len(sortValues)) + for k := range sortValues { + keys = append(keys, k) + } + return errors.Errorf("invalid sort value %q, required values: %s", c.Sort, strings.Join(keys, ", ")) + } + opts := imagesOptions{ quiet: c.Quiet, noHeading: c.Noheading, diff --git a/libpod/image/image.go b/libpod/image/image.go index 7ee8c45d7..355249b12 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -831,7 +831,8 @@ func (i *Image) History(ctx context.Context) ([]*History, error) { id := "<missing>" if x == numHistories { id = i.ID() - } else if layer != nil { + } + if layer != nil { if !oci.History[x].EmptyLayer { size = layer.UncompressedSize } diff --git a/pkg/network/files.go b/pkg/network/files.go index 92cadcf0c..116189c43 100644 --- a/pkg/network/files.go +++ b/pkg/network/files.go @@ -24,7 +24,7 @@ func LoadCNIConfsFromDir(dir string) ([]*libcni.NetworkConfigList, error) { for _, confFile := range files { conf, err := libcni.ConfListFromFile(confFile) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "in %s", confFile) } configs = append(configs, conf) } @@ -41,7 +41,7 @@ func GetCNIConfigPathByName(name string) (string, error) { for _, confFile := range files { conf, err := libcni.ConfListFromFile(confFile) if err != nil { - return "", err + return "", errors.Wrapf(err, "in %s", confFile) } if conf.Name == name { return confFile, nil diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index 80e6d4444..9a67cc83a 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -270,26 +270,36 @@ RUN apk update && apk add man Expect(result.ExitCode()).To(Equal(0)) }) - It("podman images sort by tag", func() { - session := podmanTest.Podman([]string{"images", "--sort", "tag", "--format={{.Tag}}"}) - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + It("podman images sort by values", func() { + sortValueTest := func(value string, result int, format string) []string { + f := fmt.Sprintf("{{.%s}}", format) + session := podmanTest.Podman([]string{"images", "--sort", value, "--format", f}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(result)) + + return session.OutputToStringArray() + } - sortedArr := session.OutputToStringArray() + sortedArr := sortValueTest("created", 0, "CreatedTime") + Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] > sortedArr[j] })).To(BeTrue()) + + sortedArr = sortValueTest("id", 0, "ID") Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue()) - }) - It("podman images sort by size", func() { - session := podmanTest.Podman([]string{"images", "--sort", "size", "--format={{.Size}}"}) - session.WaitWithDefaultTimeout() - Expect(session.ExitCode()).To(Equal(0)) + sortedArr = sortValueTest("repository", 0, "Repository") + Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue()) - sortedArr := session.OutputToStringArray() + sortedArr = sortValueTest("size", 0, "Size") Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { size1, _ := units.FromHumanSize(sortedArr[i]) size2, _ := units.FromHumanSize(sortedArr[j]) return size1 < size2 })).To(BeTrue()) + sortedArr = sortValueTest("tag", 0, "Tag") + Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue()) + + sortValueTest("badvalue", 125, "Tag") + sortValueTest("id", 125, "badvalue") }) It("podman images --all flag", func() { |