Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support podman ps filter regular expressions #3599

Merged
merged 1 commit into from
Jul 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cmd/podman/shared/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,11 @@ func generateContainerFilterFuncs(filter, filterValue string, r *libpod.Runtime)
}, nil
case "name":
return func(c *libpod.Container) bool {
return strings.Contains(c.Name(), filterValue)
match, err := regexp.MatchString(filterValue, c.Name())
if err != nil {
return false
}
return match
}, nil
case "exited":
exitCode, err := strconv.ParseInt(filterValue, 10, 32)
Expand Down
26 changes: 26 additions & 0 deletions test/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,30 @@ var _ = Describe("Podman ps", func() {
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToStringArray()[0]).To(Equal(fullCid))
})

It("podman ps filter name regexp", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
fullCid := session.OutputToString()

session2 := podmanTest.Podman([]string{"run", "-d", "--name", "test11", ALPINE, "top"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should fail, I think this should be named test2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I guess it is test11.

session2.WaitWithDefaultTimeout()
Expect(session2.ExitCode()).To(Equal(0))

result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "name=test1"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))

output := result.OutputToStringArray()
Expect(len(output)).To(Equal(2))

result = podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "name=test1$"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))

output = result.OutputToStringArray()
Expect(len(output)).To(Equal(1))
Expect(output[0]).To(Equal(fullCid))
})
})