2018-04-11 09:52:13 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2019-09-23 08:23:01 -04:00
|
|
|
"testing"
|
2018-04-11 09:52:13 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
2018-04-11 09:52:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ActiveContainers returns the list of ids of the currently running containers
|
2019-09-23 08:23:01 -04:00
|
|
|
func (d *Daemon) ActiveContainers(t testing.TB) []string {
|
|
|
|
t.Helper()
|
2018-04-11 09:52:13 -04:00
|
|
|
cli := d.NewClientT(t)
|
|
|
|
defer cli.Close()
|
|
|
|
|
|
|
|
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
|
|
|
|
ids := make([]string, len(containers))
|
|
|
|
for i, c := range containers {
|
|
|
|
ids[i] = c.ID
|
|
|
|
}
|
|
|
|
return ids
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindContainerIP returns the ip of the specified container
|
2019-09-23 08:23:01 -04:00
|
|
|
func (d *Daemon) FindContainerIP(t testing.TB, id string) string {
|
|
|
|
t.Helper()
|
2018-04-11 09:52:13 -04:00
|
|
|
cli := d.NewClientT(t)
|
|
|
|
defer cli.Close()
|
|
|
|
|
|
|
|
i, err := cli.ContainerInspect(context.Background(), id)
|
|
|
|
assert.NilError(t, err)
|
|
|
|
return i.NetworkSettings.IPAddress
|
|
|
|
}
|