2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
2018-01-30 12:09:56 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-02-15 10:44:00 -05:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2018-02-12 18:08:25 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
|
|
|
"gotest.tools/skip"
|
2018-01-30 12:09:56 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLinksEtcHostsContentMatch(t *testing.T) {
|
2019-01-03 06:19:15 -05:00
|
|
|
skip.If(t, testEnv.IsRemoteDaemon)
|
2018-01-30 12:09:56 -05:00
|
|
|
|
|
|
|
hosts, err := ioutil.ReadFile("/etc/hosts")
|
|
|
|
skip.If(t, os.IsNotExist(err))
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-01-30 12:09:56 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-03-12 21:08:59 -04:00
|
|
|
cID := container.Run(t, ctx, client, container.WithNetworkMode("host"))
|
|
|
|
res, err := container.Exec(ctx, client, cID, []string{"cat", "/etc/hosts"})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Assert(t, is.Len(res.Stderr(), 0))
|
|
|
|
assert.Equal(t, 0, res.ExitCode)
|
2018-01-30 12:09:56 -05:00
|
|
|
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.Equal(string(hosts), res.Stdout()))
|
2018-01-30 12:09:56 -05:00
|
|
|
}
|
2018-02-15 10:44:00 -05:00
|
|
|
|
|
|
|
func TestLinksContainerNames(t *testing.T) {
|
2018-04-19 05:14:15 -04:00
|
|
|
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
|
2018-02-15 10:44:00 -05:00
|
|
|
|
|
|
|
defer setupTest(t)()
|
2019-01-02 08:16:25 -05:00
|
|
|
client := testEnv.APIClient()
|
2018-02-15 10:44:00 -05:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-06-05 15:50:46 -04:00
|
|
|
containerA := "first_" + t.Name()
|
|
|
|
containerB := "second_" + t.Name()
|
|
|
|
container.Run(t, ctx, client, container.WithName(containerA))
|
|
|
|
container.Run(t, ctx, client, container.WithName(containerB), container.WithLinks(containerA+":"+containerA))
|
2018-02-15 10:44:00 -05:00
|
|
|
|
2018-06-05 15:50:46 -04:00
|
|
|
f := filters.NewArgs(filters.Arg("name", containerA))
|
2018-02-15 10:44:00 -05:00
|
|
|
|
|
|
|
containers, err := client.ContainerList(ctx, types.ContainerListOptions{
|
|
|
|
Filters: f,
|
|
|
|
})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(1, len(containers)))
|
2018-06-05 15:50:46 -04:00
|
|
|
assert.Check(t, is.DeepEqual([]string{"/" + containerA, "/" + containerB + "/" + containerA}, containers[0].Names))
|
2018-02-15 10:44:00 -05:00
|
|
|
}
|