mirror of https://github.com/docker/docs.git
Merge pull request #21203 from HackToday/fixfilter
Add check about filter name for containers
This commit is contained in:
commit
bd97e4f95a
|
@ -20,6 +20,19 @@ var acceptedVolumeFilterTags = map[string]bool{
|
||||||
"dangling": true,
|
"dangling": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var acceptedPsFilterTags = map[string]bool{
|
||||||
|
"ancestor": true,
|
||||||
|
"before": true,
|
||||||
|
"exited": true,
|
||||||
|
"id": true,
|
||||||
|
"isolation": true,
|
||||||
|
"label": true,
|
||||||
|
"name": true,
|
||||||
|
"status": true,
|
||||||
|
"since": true,
|
||||||
|
"volume": true,
|
||||||
|
}
|
||||||
|
|
||||||
// iterationAction represents possible outcomes happening during the container iteration.
|
// iterationAction represents possible outcomes happening during the container iteration.
|
||||||
type iterationAction int
|
type iterationAction int
|
||||||
|
|
||||||
|
@ -128,7 +141,12 @@ func (daemon *Daemon) reducePsContainer(container *container.Container, ctx *lis
|
||||||
func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listContext, error) {
|
func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listContext, error) {
|
||||||
psFilters := config.Filter
|
psFilters := config.Filter
|
||||||
|
|
||||||
|
if err := psFilters.Validate(acceptedPsFilterTags); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var filtExited []int
|
var filtExited []int
|
||||||
|
|
||||||
err := psFilters.WalkValues("exited", func(value string) error {
|
err := psFilters.WalkValues("exited", func(value string) error {
|
||||||
code, err := strconv.Atoi(value)
|
code, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -213,6 +213,12 @@ func assertContainerList(out string, expected []string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestPsListContainersInvalidFilterName(c *check.C) {
|
||||||
|
out, _, err := dockerCmdWithError("ps", "-f", "invalidFilter=test")
|
||||||
|
c.Assert(err, checker.NotNil)
|
||||||
|
c.Assert(out, checker.Contains, "Invalid filter")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
func (s *DockerSuite) TestPsListContainersSize(c *check.C) {
|
||||||
// Problematic on Windows as it doesn't report the size correctly @swernli
|
// Problematic on Windows as it doesn't report the size correctly @swernli
|
||||||
testRequires(c, DaemonIsLinux)
|
testRequires(c, DaemonIsLinux)
|
||||||
|
|
Loading…
Reference in New Issue