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-02-09 13:13:26 -05:00
|
|
|
"github.com/docker/docker/integration/internal/request"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-01-04 20:50:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPsFilter(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
|
|
|
client := request.NewAPIClient(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-03-21 17:47:49 -04:00
|
|
|
prev := container.Create(t, ctx, client, container.WithName("prev-"+t.Name()))
|
|
|
|
topContainerName := "top-" + t.Name()
|
|
|
|
container.Create(t, ctx, client, container.WithName(topContainerName))
|
|
|
|
next := container.Create(t, ctx, client, container.WithName("next-"+t.Name()))
|
2018-01-04 20:50:58 -05:00
|
|
|
|
|
|
|
containerIDs := func(containers []types.Container) []string {
|
|
|
|
entries := []string{}
|
|
|
|
for _, container := range containers {
|
|
|
|
entries = append(entries, container.ID)
|
|
|
|
}
|
|
|
|
return entries
|
|
|
|
}
|
|
|
|
|
|
|
|
f1 := filters.NewArgs()
|
2018-03-21 17:47:49 -04:00
|
|
|
f1.Add("since", topContainerName)
|
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-21 17:47:49 -04:00
|
|
|
f2.Add("before", topContainerName)
|
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
|
|
|
}
|