github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/integration/container/links_linux_test.go (about)

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