I am not quite sure why but this test is sometimes failing like this:
> 15:21:41 --- FAIL: TestLinksEtcHostsContentMatch (0.53s)
> 15:21:41 assertions.go:226:
>
> Error Trace: links_linux_test.go:46
> 15:21:41
> Error: Not equal:
> 15:21:41
> expected: "127.0.0.1\tlocalhost\n::1\tlocalhost
> ip6-localhost
> ip6-loopback\nfe00::0\tip6-localnet\nff00::0\tip6-mcastprefix\nff02::1\tip6-allnodes\nff02::2\tip6-allrouters\n172.17.0.2\tf53feb6df161\n"
> 15:21:41
> received: ""
To eliminate some possible failures (like ignoring stderr from `cat` or
its exit code), let's use container.Exec() to read a file from a container.
Fixes: e6bd20edcbf ("Migrate some integration-cli test to api tests")
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Upstream-commit: ad2f88d8ccbd9dd0a8d9c4f96ece3956f60489df
Component: engine
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package container // import "github.com/docker/docker/integration/container"
|
|
|
|
import (
|
|
"context"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/integration/internal/container"
|
|
"github.com/docker/docker/integration/internal/request"
|
|
"github.com/gotestyourself/gotestyourself/skip"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestLinksEtcHostsContentMatch(t *testing.T) {
|
|
skip.If(t, testEnv.IsRemoteDaemon())
|
|
|
|
hosts, err := ioutil.ReadFile("/etc/hosts")
|
|
skip.If(t, os.IsNotExist(err))
|
|
|
|
defer setupTest(t)()
|
|
client := request.NewAPIClient(t)
|
|
ctx := context.Background()
|
|
|
|
cID := container.Run(t, ctx, client, container.WithNetworkMode("host"))
|
|
res, err := container.Exec(ctx, client, cID, []string{"cat", "/etc/hosts"})
|
|
require.NoError(t, err)
|
|
require.Empty(t, res.Stderr())
|
|
require.Equal(t, 0, res.ExitCode)
|
|
|
|
assert.Equal(t, string(hosts), res.Stdout())
|
|
}
|
|
|
|
func TestLinksContainerNames(t *testing.T) {
|
|
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
|
|
|
|
defer setupTest(t)()
|
|
client := request.NewAPIClient(t)
|
|
ctx := context.Background()
|
|
|
|
container.Run(t, ctx, client, container.WithName("first"))
|
|
container.Run(t, ctx, client, container.WithName("second"), container.WithLinks("first:first"))
|
|
|
|
f := filters.NewArgs(filters.Arg("name", "first"))
|
|
|
|
containers, err := client.ContainerList(ctx, types.ContainerListOptions{
|
|
Filters: f,
|
|
})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 1, len(containers))
|
|
assert.Equal(t, []string{"/first", "/second/first"}, containers[0].Names)
|
|
}
|