aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-01-28 15:05:30 -0800
committerGitHub <noreply@github.com>2020-01-28 15:05:30 -0800
commit50eaf6de92b4e9feef9adba41e2b14f3cf3a0809 (patch)
treef92211c1696e68180aa7d7d207c596090c80d9c5
parent66bb873390badc4ad88620d211de09b4668d1cd5 (diff)
parent38d2ef0cbd32a68a6d2c74b35d75fd9b14a3867a (diff)
downloadpodman-50eaf6de92b4e9feef9adba41e2b14f3cf3a0809.tar.gz
podman-50eaf6de92b4e9feef9adba41e2b14f3cf3a0809.tar.bz2
podman-50eaf6de92b4e9feef9adba41e2b14f3cf3a0809.zip
Merge pull request #4973 from rhatdan/sort
Throw error on invalid sort value
-rw-r--r--cmd/podman/images.go15
-rw-r--r--test/e2e/images_test.go32
2 files changed, 36 insertions, 11 deletions
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/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() {