github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/testutil/daemon/container.go (about)

     1  package daemon
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/demonoid81/moby/api/types"
     8  	"gotest.tools/v3/assert"
     9  )
    10  
    11  // ActiveContainers returns the list of ids of the currently running containers
    12  func (d *Daemon) ActiveContainers(t testing.TB) []string {
    13  	t.Helper()
    14  	cli := d.NewClientT(t)
    15  	defer cli.Close()
    16  
    17  	containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
    18  	assert.NilError(t, err)
    19  
    20  	ids := make([]string, len(containers))
    21  	for i, c := range containers {
    22  		ids[i] = c.ID
    23  	}
    24  	return ids
    25  }
    26  
    27  // FindContainerIP returns the ip of the specified container
    28  func (d *Daemon) FindContainerIP(t testing.TB, id string) string {
    29  	t.Helper()
    30  	cli := d.NewClientT(t)
    31  	defer cli.Close()
    32  
    33  	i, err := cli.ContainerInspect(context.Background(), id)
    34  	assert.NilError(t, err)
    35  	return i.NetworkSettings.IPAddress
    36  }