Add test case for before
and since
filter for docker ps
This fix adds an integration test for `before` and `since` filter for `docker ps` Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
9833332dba
commit
52b44b9816
1 changed files with 64 additions and 0 deletions
64
integration/container/ps_test.go
Normal file
64
integration/container/ps_test.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Reference in a new issue