mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Migrate some integration-cli test to api tests
This fix migrate TestLinksEtcHostsContentMatch to api test. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
40a9d5d24c
commit
e6bd20edcb
2 changed files with 59 additions and 26 deletions
|
@ -1,26 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/go-check/check"
|
||||
)
|
||||
|
||||
func (s *DockerSuite) TestLinksEtcHostsContentMatch(c *check.C) {
|
||||
// In a _unix file as using Unix specific files, and must be on the
|
||||
// same host as the daemon.
|
||||
testRequires(c, SameHostDaemon, NotUserNamespace)
|
||||
|
||||
out, _ := dockerCmd(c, "run", "--net=host", "busybox", "cat", "/etc/hosts")
|
||||
hosts, err := ioutil.ReadFile("/etc/hosts")
|
||||
if os.IsNotExist(err) {
|
||||
c.Skip("/etc/hosts does not exist, skip this test")
|
||||
}
|
||||
|
||||
c.Assert(out, checker.Equals, string(hosts), check.Commentf("container: %s\n\nhost:%s", out, hosts))
|
||||
|
||||
}
|
59
integration/container/links_linux_test.go
Normal file
59
integration/container/links_linux_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/integration/util/request"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/gotestyourself/gotestyourself/poll"
|
||||
"github.com/gotestyourself/gotestyourself/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestLinksEtcHostsContentMatch(t *testing.T) {
|
||||
skip.If(t, !testEnv.IsLocalDaemon())
|
||||
|
||||
hosts, err := ioutil.ReadFile("/etc/hosts")
|
||||
skip.If(t, os.IsNotExist(err))
|
||||
|
||||
defer setupTest(t)()
|
||||
client := request.NewAPIClient(t)
|
||||
ctx := context.Background()
|
||||
|
||||
c, err := client.ContainerCreate(ctx,
|
||||
&container.Config{
|
||||
Image: "busybox",
|
||||
Cmd: []string{"cat", "/etc/hosts"},
|
||||
},
|
||||
&container.HostConfig{
|
||||
NetworkMode: "host",
|
||||
},
|
||||
nil,
|
||||
"")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
poll.WaitOn(t, containerIsStopped(ctx, client, c.ID), poll.WithDelay(100*time.Millisecond))
|
||||
|
||||
body, err := client.ContainerLogs(ctx, c.ID, types.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer body.Close()
|
||||
|
||||
var b bytes.Buffer
|
||||
_, err = stdcopy.StdCopy(&b, ioutil.Discard, body)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, string(hosts), b.String())
|
||||
}
|
Loading…
Reference in a new issue