Skip to content

Commit

Permalink
fix ps --last=N
Browse files Browse the repository at this point in the history
Fix `ps --last=N` to also include non-running containers. Also add an
e2e test to prevent us from regressing in the future.

Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed May 28, 2020
1 parent adca437 commit d6469c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/ps/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetContainerLists(runtime *libpod.Runtime, options entities.ContainerListOp
filterFuncs []libpod.ContainerFilter
pss []entities.ListContainer
)
all := options.All
all := options.All || options.Last > 0
if len(options.Filters) > 0 {
for k, v := range options.Filters {
for _, val := range v {
Expand Down
25 changes: 23 additions & 2 deletions test/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ var _ = Describe("Podman ps", func() {
It("podman ps last flag", func() {
Skip("--last flag nonfunctional and disabled")

// Make sure that non-running containers are being counted as
// well.
session := podmanTest.Podman([]string{"create", "alpine", "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))

result := podmanTest.Podman([]string{"ps", "--last", "2"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(2)) // 1 container

_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))

Expand All @@ -123,10 +134,20 @@ var _ = Describe("Podman ps", func() {
_, ec, _ = podmanTest.RunLsContainer("test3")
Expect(ec).To(Equal(0))

result := podmanTest.Podman([]string{"ps", "--last", "2"})
result = podmanTest.Podman([]string{"ps", "--last", "2"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(3)) // 2 containers

result = podmanTest.Podman([]string{"ps", "--last", "3"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(4)) // 3 containers

result = podmanTest.Podman([]string{"ps", "--last", "100"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(len(result.OutputToStringArray())).Should(Equal(3))
Expect(len(result.OutputToStringArray())).Should(Equal(5)) // 4 containers (3 running + 1 created)
})

It("podman ps no-trunc", func() {
Expand Down

0 comments on commit d6469c9

Please sign in to comment.