2018-02-05 21:05:59 +00:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
2018-01-05 01:50:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/filters"
|
2018-02-28 21:35:56 +00:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2020-02-07 13:39:24 +00:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2018-01-05 01:50:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPsFilter(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
2019-01-02 13:16:25 +00:00
|
|
|
client := testEnv.APIClient()
|
2018-01-05 01:50:58 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2019-06-06 11:00:37 +00:00
|
|
|
prev := container.Create(ctx, t, client)
|
|
|
|
top := container.Create(ctx, t, client)
|
|
|
|
next := container.Create(ctx, t, client)
|
2018-01-05 01:50:58 +00:00
|
|
|
|
|
|
|
containerIDs := func(containers []types.Container) []string {
|
2018-05-19 11:38:54 +00:00
|
|
|
var entries []string
|
2018-01-05 01:50:58 +00:00
|
|
|
for _, container := range containers {
|
|
|
|
entries = append(entries, container.ID)
|
|
|
|
}
|
|
|
|
return entries
|
|
|
|
}
|
|
|
|
|
|
|
|
f1 := filters.NewArgs()
|
2018-03-27 16:13:47 +00:00
|
|
|
f1.Add("since", top)
|
2018-01-05 01:50:58 +00:00
|
|
|
q1, err := client.ContainerList(ctx, types.ContainerListOptions{
|
|
|
|
All: true,
|
|
|
|
Filters: f1,
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(containerIDs(q1), next))
|
2018-01-05 01:50:58 +00:00
|
|
|
|
|
|
|
f2 := filters.NewArgs()
|
2018-03-27 16:13:47 +00:00
|
|
|
f2.Add("before", top)
|
2018-01-05 01:50:58 +00:00
|
|
|
q2, err := client.ContainerList(ctx, types.ContainerListOptions{
|
|
|
|
All: true,
|
|
|
|
Filters: f2,
|
|
|
|
})
|
2018-03-13 19:28:34 +00:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Contains(containerIDs(q2), prev))
|
2018-01-05 01:50:58 +00:00
|
|
|
}
|