mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Test invalid filter and move validation on top
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
1690103906
commit
05e7f2cf58
3 changed files with 30 additions and 11 deletions
|
@ -182,6 +182,10 @@ func (daemon *Daemon) filterByNameIDMatches(view container.View, ctx *listContex
|
||||||
|
|
||||||
// reduceContainers parses the user's filtering options and generates the list of containers to return based on a reducer.
|
// reduceContainers parses the user's filtering options and generates the list of containers to return based on a reducer.
|
||||||
func (daemon *Daemon) reduceContainers(config *types.ContainerListOptions, reducer containerReducer) ([]*types.Container, error) {
|
func (daemon *Daemon) reduceContainers(config *types.ContainerListOptions, reducer containerReducer) ([]*types.Container, error) {
|
||||||
|
if err := config.Filters.Validate(acceptedPsFilterTags); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
view = daemon.containersReplica.Snapshot()
|
view = daemon.containersReplica.Snapshot()
|
||||||
containers = []*types.Container{}
|
containers = []*types.Container{}
|
||||||
|
@ -246,10 +250,6 @@ func (daemon *Daemon) reducePsContainer(container *container.Snapshot, ctx *list
|
||||||
func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerListOptions) (*listContext, error) {
|
func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerListOptions) (*listContext, error) {
|
||||||
psFilters := config.Filters
|
psFilters := config.Filters
|
||||||
|
|
||||||
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 {
|
||||||
|
|
26
daemon/list_test.go
Normal file
26
daemon/list_test.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package daemon
|
||||||
|
|
||||||
|
import(
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/container"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/filters"
|
||||||
|
"github.com/gotestyourself/gotestyourself/assert"
|
||||||
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestListInvalidFilter(t *testing.T) {
|
||||||
|
db, err := container.NewViewDB()
|
||||||
|
assert.Assert(t, err == nil)
|
||||||
|
d := &Daemon{
|
||||||
|
containersReplica: db,
|
||||||
|
}
|
||||||
|
|
||||||
|
f := filters.NewArgs(filters.Arg("invalid", "foo"))
|
||||||
|
|
||||||
|
_, err = d.Containers(&types.ContainerListOptions{
|
||||||
|
Filters: f,
|
||||||
|
})
|
||||||
|
assert.Assert(t, is.Error(err, "Invalid filter 'invalid'"))
|
||||||
|
}
|
|
@ -139,13 +139,6 @@ func assertContainerList(out string, expected []string) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(vdemeester) Move this into a unit test in daemon package
|
|
||||||
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 a new issue