From 4ab054073dadf5257bdd0ff21e154b859e139f1e Mon Sep 17 00:00:00 2001 From: haircommander Date: Thu, 14 Jun 2018 15:29:46 -0400 Subject: Added --sort to ps Also podman ps now allows user to only output size of root FS, changed language of images and ps --sort to be by "created" as opposed to "time", and refactored the way templates are created (converted from psJSONParams type). Signed-off-by: haircommander Closes: #948 Approved by: rhatdan --- test/e2e/ps_test.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index feb0628b3..38b59e1d1 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -1,10 +1,12 @@ package integration import ( - "os" - "fmt" + "os" + "regexp" + "sort" + "github.com/docker/go-units" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -186,4 +188,60 @@ var _ = Describe("Podman ps", func() { session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Not(Equal(0))) }) + + It("podman --sort by size", func() { + // these images chosen because their size would be sorted differently alphabetically vs + // by the size of their virtual fs + session := podmanTest.Podman([]string{"run", "docker.io/mattdm/fedora-small", "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + podmanTest.RestoreArtifact(nginx) + session = podmanTest.Podman([]string{"run", "-dt", "-P", "docker.io/library/nginx:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"ps", "-a", "--sort=size", "--format", "{{.Size}}"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + sortedArr := session.OutputToStringArray() + + Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { + r := regexp.MustCompile(`^\S+\s+\(virtual (\S+)\)`) + matches1 := r.FindStringSubmatch(sortedArr[i]) + matches2 := r.FindStringSubmatch(sortedArr[j]) + + // sanity check in case an oddly formatted size appears + if len(matches1) < 2 || len(matches2) < 2 { + return sortedArr[i] < sortedArr[j] + } else { + size1, _ := units.FromHumanSize(matches1[1]) + size2, _ := units.FromHumanSize(matches2[1]) + return size1 < size2 + } + })).To(BeTrue()) + + }) + + It("podman --sort by command", func() { + session := podmanTest.RunTopContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + podmanTest.RestoreArtifact(nginx) + session = podmanTest.Podman([]string{"run", "-d", fedoraMinimal, "pwd"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"ps", "-a", "--sort=command", "--format", "{{.Command}}"}) + + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + sortedArr := session.OutputToStringArray() + + Expect(sort.SliceIsSorted(sortedArr, func(i, j int) bool { return sortedArr[i] < sortedArr[j] })).To(BeTrue()) + + }) }) -- cgit v1.2.3-54-g00ecf