github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/container/ps_test.go (about) 1 package container // import "github.com/demonoid81/moby/integration/container" 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/demonoid81/moby/api/types" 8 "github.com/demonoid81/moby/api/types/filters" 9 "github.com/demonoid81/moby/integration/internal/container" 10 "gotest.tools/v3/assert" 11 is "gotest.tools/v3/assert/cmp" 12 ) 13 14 func TestPsFilter(t *testing.T) { 15 defer setupTest(t)() 16 client := testEnv.APIClient() 17 ctx := context.Background() 18 19 prev := container.Create(ctx, t, client) 20 top := container.Create(ctx, t, client) 21 next := container.Create(ctx, t, client) 22 23 containerIDs := func(containers []types.Container) []string { 24 var entries []string 25 for _, container := range containers { 26 entries = append(entries, container.ID) 27 } 28 return entries 29 } 30 31 f1 := filters.NewArgs() 32 f1.Add("since", top) 33 q1, err := client.ContainerList(ctx, types.ContainerListOptions{ 34 All: true, 35 Filters: f1, 36 }) 37 assert.NilError(t, err) 38 assert.Check(t, is.Contains(containerIDs(q1), next)) 39 40 f2 := filters.NewArgs() 41 f2.Add("before", top) 42 q2, err := client.ContainerList(ctx, types.ContainerListOptions{ 43 All: true, 44 Filters: f2, 45 }) 46 assert.NilError(t, err) 47 assert.Check(t, is.Contains(containerIDs(q2), prev)) 48 }