mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
Merge pull request #8238 from joelsmith/master
Use regex for "pod ps" name filter to match "ps" behavior
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package lpfilters
|
package lpfilters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -78,7 +79,11 @@ func GeneratePodFilterFunc(filter, filterValue string) (
|
|||||||
}, nil
|
}, nil
|
||||||
case "name":
|
case "name":
|
||||||
return func(p *libpod.Pod) bool {
|
return func(p *libpod.Pod) bool {
|
||||||
return strings.Contains(p.Name(), filterValue)
|
match, err := regexp.MatchString(filterValue, p.Name())
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return match
|
||||||
}, nil
|
}, nil
|
||||||
case "status":
|
case "status":
|
||||||
if !util.StringInSlice(filterValue, []string{"stopped", "running", "paused", "exited", "dead", "created"}) {
|
if !util.StringInSlice(filterValue, []string{"stopped", "running", "paused", "exited", "dead", "created"}) {
|
||||||
|
@ -107,6 +107,28 @@ var _ = Describe("Podman ps", func() {
|
|||||||
Expect(result.ExitCode()).To(Equal(0))
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman pod ps filter name regexp", func() {
|
||||||
|
_, ec, podid := podmanTest.CreatePod("mypod")
|
||||||
|
Expect(ec).To(Equal(0))
|
||||||
|
_, ec2, _ := podmanTest.CreatePod("mypod1")
|
||||||
|
Expect(ec2).To(Equal(0))
|
||||||
|
|
||||||
|
result := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "name=mypod"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
output := result.OutputToStringArray()
|
||||||
|
Expect(len(output)).To(Equal(2))
|
||||||
|
|
||||||
|
result = podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc", "--filter", "name=mypod$"})
|
||||||
|
result.WaitWithDefaultTimeout()
|
||||||
|
Expect(result.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
output = result.OutputToStringArray()
|
||||||
|
Expect(len(output)).To(Equal(1))
|
||||||
|
Expect(output[0]).To(Equal(podid))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman pod ps mutually exclusive flags", func() {
|
It("podman pod ps mutually exclusive flags", func() {
|
||||||
session := podmanTest.Podman([]string{"pod", "ps", "-q", "--format", "{{.ID}}"})
|
session := podmanTest.Podman([]string{"pod", "ps", "-q", "--format", "{{.ID}}"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user