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>
| ... | ... |
@@ -1,19 +1,15 @@ |
| 1 | 1 |
package container // import "github.com/docker/docker/integration/container" |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "bytes" |
|
| 5 | 4 |
"context" |
| 6 | 5 |
"io/ioutil" |
| 7 | 6 |
"os" |
| 8 | 7 |
"testing" |
| 9 |
- "time" |
|
| 10 | 8 |
|
| 11 | 9 |
"github.com/docker/docker/api/types" |
| 12 | 10 |
"github.com/docker/docker/api/types/filters" |
| 13 | 11 |
"github.com/docker/docker/integration/internal/container" |
| 14 | 12 |
"github.com/docker/docker/integration/internal/request" |
| 15 |
- "github.com/docker/docker/pkg/stdcopy" |
|
| 16 |
- "github.com/gotestyourself/gotestyourself/poll" |
|
| 17 | 13 |
"github.com/gotestyourself/gotestyourself/skip" |
| 18 | 14 |
"github.com/stretchr/testify/assert" |
| 19 | 15 |
"github.com/stretchr/testify/require" |
| ... | ... |
@@ -29,21 +25,13 @@ func TestLinksEtcHostsContentMatch(t *testing.T) {
|
| 29 | 29 |
client := request.NewAPIClient(t) |
| 30 | 30 |
ctx := context.Background() |
| 31 | 31 |
|
| 32 |
- cID := container.Run(t, ctx, client, container.WithCmd("cat", "/etc/hosts"), container.WithNetworkMode("host"))
|
|
| 33 |
- |
|
| 34 |
- poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond)) |
|
| 35 |
- |
|
| 36 |
- body, err := client.ContainerLogs(ctx, cID, types.ContainerLogsOptions{
|
|
| 37 |
- ShowStdout: true, |
|
| 38 |
- }) |
|
| 39 |
- require.NoError(t, err) |
|
| 40 |
- defer body.Close() |
|
| 41 |
- |
|
| 42 |
- var b bytes.Buffer |
|
| 43 |
- _, err = stdcopy.StdCopy(&b, ioutil.Discard, body) |
|
| 32 |
+ cID := container.Run(t, ctx, client, container.WithNetworkMode("host"))
|
|
| 33 |
+ res, err := container.Exec(ctx, client, cID, []string{"cat", "/etc/hosts"})
|
|
| 44 | 34 |
require.NoError(t, err) |
| 35 |
+ require.Empty(t, res.Stderr()) |
|
| 36 |
+ require.Equal(t, 0, res.ExitCode) |
|
| 45 | 37 |
|
| 46 |
- assert.Equal(t, string(hosts), b.String()) |
|
| 38 |
+ assert.Equal(t, string(hosts), res.Stdout()) |
|
| 47 | 39 |
} |
| 48 | 40 |
|
| 49 | 41 |
func TestLinksContainerNames(t *testing.T) {
|