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"
|
|
|
|
"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"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
|
|
|
"gotest.tools/v3/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)
|
2020-02-18 04:43:56 -05:00
|
|
|
skip.If(t, testEnv.IsRootless, "rootless mode has different view of /etc/hosts")
|
2018-01-30 12:09:56 -05:00
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
hosts, err := os.ReadFile("/etc/hosts")
|
2018-01-30 12:09:56 -05:00
|
|
|
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()
|
|
|
|
|
2019-06-06 07:15:31 -04:00
|
|
|
cID := container.Run(ctx, t, client, container.WithNetworkMode("host"))
|
2018-03-12 21:08:59 -04:00
|
|
|
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()
|
2019-06-06 07:15:31 -04:00
|
|
|
container.Run(ctx, t, client, container.WithName(containerA))
|
|
|
|
container.Run(ctx, t, 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
|
|
|
}
|