github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/integration/container/ps_test.go (about)

     1  package container // import "github.com/docker/docker/integration/container"
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"github.com/docker/docker/api/types/filters"
     9  	"github.com/docker/docker/integration/internal/container"
    10  	"gotest.tools/assert"
    11  	is "gotest.tools/assert/cmp"
    12  )
    13  
    14  func TestPsFilter(t *testing.T) {
    15  	defer setupTest(t)()
    16  	client := testEnv.APIClient()
    17  	ctx := context.Background()
    18  
    19  	prev := container.Create(t, ctx, client)
    20  	top := container.Create(t, ctx, client)
    21  	next := container.Create(t, ctx, client)
    22  
    23  	containerIDs := func(containers []types.Container) []string {
    24  		var entries []string
    25  		for _, container := range containers {
    26  			entries = append(entries, container.ID)
    27  		}
    28  		return entries
    29  	}
    30  
    31  	f1 := filters.NewArgs()
    32  	f1.Add("since", top)
    33  	q1, err := client.ContainerList(ctx, types.ContainerListOptions{
    34  		All:     true,
    35  		Filters: f1,
    36  	})
    37  	assert.NilError(t, err)
    38  	assert.Check(t, is.Contains(containerIDs(q1), next))
    39  
    40  	f2 := filters.NewArgs()
    41  	f2.Add("before", top)
    42  	q2, err := client.ContainerList(ctx, types.ContainerListOptions{
    43  		All:     true,
    44  		Filters: f2,
    45  	})
    46  	assert.NilError(t, err)
    47  	assert.Check(t, is.Contains(containerIDs(q2), prev))
    48  }