github.com/rumpl/bof@v23.0.0-rc.2+incompatible/integration/container/links_linux_test.go (about) 1 package container // import "github.com/docker/docker/integration/container" 2 3 import ( 4 "context" 5 "os" 6 "testing" 7 8 "github.com/docker/docker/api/types" 9 "github.com/docker/docker/api/types/filters" 10 "github.com/docker/docker/integration/internal/container" 11 "gotest.tools/v3/assert" 12 is "gotest.tools/v3/assert/cmp" 13 "gotest.tools/v3/skip" 14 ) 15 16 func TestLinksEtcHostsContentMatch(t *testing.T) { 17 skip.If(t, testEnv.IsRemoteDaemon) 18 skip.If(t, testEnv.IsRootless, "rootless mode has different view of /etc/hosts") 19 20 hosts, err := os.ReadFile("/etc/hosts") 21 skip.If(t, os.IsNotExist(err)) 22 23 defer setupTest(t)() 24 client := testEnv.APIClient() 25 ctx := context.Background() 26 27 cID := container.Run(ctx, t, client, container.WithNetworkMode("host")) 28 res, err := container.Exec(ctx, client, cID, []string{"cat", "/etc/hosts"}) 29 assert.NilError(t, err) 30 assert.Assert(t, is.Len(res.Stderr(), 0)) 31 assert.Equal(t, 0, res.ExitCode) 32 33 assert.Check(t, is.Equal(string(hosts), res.Stdout())) 34 } 35 36 func TestLinksContainerNames(t *testing.T) { 37 skip.If(t, testEnv.DaemonInfo.OSType == "windows") 38 39 defer setupTest(t)() 40 client := testEnv.APIClient() 41 ctx := context.Background() 42 43 containerA := "first_" + t.Name() 44 containerB := "second_" + t.Name() 45 container.Run(ctx, t, client, container.WithName(containerA)) 46 container.Run(ctx, t, client, container.WithName(containerB), container.WithLinks(containerA+":"+containerA)) 47 48 f := filters.NewArgs(filters.Arg("name", containerA)) 49 50 containers, err := client.ContainerList(ctx, types.ContainerListOptions{ 51 Filters: f, 52 }) 53 assert.NilError(t, err) 54 assert.Check(t, is.Equal(1, len(containers))) 55 assert.Check(t, is.DeepEqual([]string{"/" + containerA, "/" + containerB + "/" + containerA}, containers[0].Names)) 56 }