diff options
author | Qi Wang <qiwan@redhat.com> | 2019-07-18 13:10:37 -0400 |
---|---|---|
committer | Qi Wang <qiwan@redhat.com> | 2019-07-18 13:11:04 -0400 |
commit | 5047c79e71a336da1fa2e0b8fc6e50811801f878 (patch) | |
tree | 8d4eab3628304525286a5612ad78b1c721e90a58 | |
parent | adcde2383f1da517c5788516d639745f5f01d300 (diff) | |
download | podman-5047c79e71a336da1fa2e0b8fc6e50811801f878.tar.gz podman-5047c79e71a336da1fa2e0b8fc6e50811801f878.tar.bz2 podman-5047c79e71a336da1fa2e0b8fc6e50811801f878.zip |
support podman ps filter regular expressions
podman ps --filter use regexp to match the container name.
Signed-off-by: Qi Wang <qiwan@redhat.com>
-rw-r--r-- | cmd/podman/shared/container.go | 6 | ||||
-rw-r--r-- | test/e2e/ps_test.go | 26 |
2 files changed, 31 insertions, 1 deletions
diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go index 3c68a29b4..5492f843f 100644 --- a/cmd/podman/shared/container.go +++ b/cmd/podman/shared/container.go @@ -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) diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index 2b86f663f..efcf44f76 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -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"}) + 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)) + }) }) |