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