mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
52b44b9816
This fix adds an integration test for `before` and `since` filter for `docker ps` Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/container"
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/api/types/network"
|
|
"github.com/docker/docker/integration/util/request"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestPsFilter(t *testing.T) {
|
|
defer setupTest(t)()
|
|
client := request.NewAPIClient(t)
|
|
ctx := context.Background()
|
|
|
|
createContainerForFilter := func(ctx context.Context, name string) string {
|
|
body, err := client.ContainerCreate(ctx,
|
|
&container.Config{
|
|
Cmd: []string{"top"},
|
|
Image: "busybox",
|
|
},
|
|
&container.HostConfig{},
|
|
&network.NetworkingConfig{},
|
|
name,
|
|
)
|
|
require.NoError(t, err)
|
|
return body.ID
|
|
}
|
|
|
|
prev := createContainerForFilter(ctx, "prev")
|
|
createContainerForFilter(ctx, "top")
|
|
next := createContainerForFilter(ctx, "next")
|
|
|
|
containerIDs := func(containers []types.Container) []string {
|
|
entries := []string{}
|
|
for _, container := range containers {
|
|
entries = append(entries, container.ID)
|
|
}
|
|
return entries
|
|
}
|
|
|
|
f1 := filters.NewArgs()
|
|
f1.Add("since", "top")
|
|
q1, err := client.ContainerList(ctx, types.ContainerListOptions{
|
|
All: true,
|
|
Filters: f1,
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Contains(t, containerIDs(q1), next)
|
|
|
|
f2 := filters.NewArgs()
|
|
f2.Add("before", "top")
|
|
q2, err := client.ContainerList(ctx, types.ContainerListOptions{
|
|
All: true,
|
|
Filters: f2,
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Contains(t, containerIDs(q2), prev)
|
|
}
|