moby/integration/container/links_linux_test.go
Sebastiaan van Stijn 26be2bc6b9
integration/container: use consistent name for api-client
The `client` variable was colliding with the `client` import in various
files. While it didn't conflict in all files, there was inconsistency
in the naming, sometimes using the confusing `cli` name (it's not the
"cli"), and such names can easily start spreading (through copy/paste,
or "code by example").

Let's make a one-time pass through all of them in this package to use
the same name.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-08-11 13:51:57 +02:00

54 lines
1.7 KiB
Go

package container // import "github.com/docker/docker/integration/container"
import (
"context"
"os"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/integration/internal/container"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/skip"
)
func TestLinksEtcHostsContentMatch(t *testing.T) {
skip.If(t, testEnv.IsRemoteDaemon)
skip.If(t, testEnv.IsRootless, "rootless mode has different view of /etc/hosts")
hosts, err := os.ReadFile("/etc/hosts")
skip.If(t, os.IsNotExist(err))
defer setupTest(t)()
apiClient := testEnv.APIClient()
ctx := context.Background()
cID := container.Run(ctx, t, apiClient, container.WithNetworkMode("host"))
res, err := container.Exec(ctx, apiClient, cID, []string{"cat", "/etc/hosts"})
assert.NilError(t, err)
assert.Assert(t, is.Len(res.Stderr(), 0))
assert.Equal(t, 0, res.ExitCode)
assert.Check(t, is.Equal(string(hosts), res.Stdout()))
}
func TestLinksContainerNames(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
defer setupTest(t)()
apiClient := testEnv.APIClient()
ctx := context.Background()
containerA := "first_" + t.Name()
containerB := "second_" + t.Name()
container.Run(ctx, t, apiClient, container.WithName(containerA))
container.Run(ctx, t, apiClient, container.WithName(containerB), container.WithLinks(containerA+":"+containerA))
containers, err := apiClient.ContainerList(ctx, types.ContainerListOptions{
Filters: filters.NewArgs(filters.Arg("name", containerA)),
})
assert.NilError(t, err)
assert.Check(t, is.Equal(1, len(containers)))
assert.Check(t, is.DeepEqual([]string{"/" + containerA, "/" + containerB + "/" + containerA}, containers[0].Names))
}