Browse Source

integration-cli: DockerCLILinksSuite: replace dockerCmd and waitRun

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 năm trước cách đây
mục cha
commit
d3f4580519

+ 45 - 50
integration-cli/docker_cli_links_test.go

@@ -9,6 +9,7 @@ import (
 	"strings"
 	"strings"
 	"testing"
 	"testing"
 
 
+	"github.com/docker/docker/integration-cli/cli"
 	"github.com/docker/docker/runconfig"
 	"github.com/docker/docker/runconfig"
 	"gotest.tools/v3/assert"
 	"gotest.tools/v3/assert"
 	is "gotest.tools/v3/assert/cmp"
 	is "gotest.tools/v3/assert/cmp"
@@ -62,8 +63,8 @@ func testLinkPingOnNetwork(c *testing.T, network string) {
 	runArgs2 := append([]string{"run", "-d", "--name", "container2", "--hostname", "wilma"}, postArgs...)
 	runArgs2 := append([]string{"run", "-d", "--name", "container2", "--hostname", "wilma"}, postArgs...)
 
 
 	// Run the two named containers
 	// Run the two named containers
-	dockerCmd(c, runArgs1...)
-	dockerCmd(c, runArgs2...)
+	cli.DockerCmd(c, runArgs1...)
+	cli.DockerCmd(c, runArgs2...)
 
 
 	postArgs = []string{}
 	postArgs = []string{}
 	if network != "" {
 	if network != "" {
@@ -77,34 +78,32 @@ func testLinkPingOnNetwork(c *testing.T, network string) {
 
 
 	// test ping by alias, ping by name, and ping by hostname
 	// test ping by alias, ping by name, and ping by hostname
 	// 1. Ping by alias
 	// 1. Ping by alias
-	dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...)
+	cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "alias1", "alias2"))...)
 	// 2. Ping by container name
 	// 2. Ping by container name
-	dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...)
+	cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "container1", "container2"))...)
 	// 3. Ping by hostname
 	// 3. Ping by hostname
-	dockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
+	cli.DockerCmd(c, append(runArgs, fmt.Sprintf(pingCmd, "fred", "wilma"))...)
 
 
 	// Clean for next round
 	// Clean for next round
-	dockerCmd(c, "rm", "-f", "container1")
-	dockerCmd(c, "rm", "-f", "container2")
+	cli.DockerCmd(c, "rm", "-f", "container1")
+	cli.DockerCmd(c, "rm", "-f", "container2")
 }
 }
 
 
 func (s *DockerCLILinksSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksPingLinkedContainersAfterRename(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
-	out, _ := dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
-	idA := strings.TrimSpace(out)
-	out, _ = dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
-	idB := strings.TrimSpace(out)
-	dockerCmd(c, "rename", "container1", "container_new")
-	dockerCmd(c, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
-	dockerCmd(c, "kill", idA)
-	dockerCmd(c, "kill", idB)
+	idA := cli.DockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top").Stdout()
+	idB := cli.DockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top").Stdout()
+	cli.DockerCmd(c, "rename", "container1", "container_new")
+	cli.DockerCmd(c, "run", "--rm", "--link", "container_new:alias1", "--link", "container2:alias2", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1")
+	cli.DockerCmd(c, "kill", strings.TrimSpace(idA))
+	cli.DockerCmd(c, "kill", strings.TrimSpace(idB))
 }
 }
 
 
 func (s *DockerCLILinksSuite) TestLinksInspectLinksStarted(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksInspectLinksStarted(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
-	dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
-	dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
-	dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
+	cli.DockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
+	cli.DockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
+	cli.DockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "top")
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
 
 
 	var result []string
 	var result []string
@@ -122,9 +121,9 @@ func (s *DockerCLILinksSuite) TestLinksInspectLinksStarted(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksInspectLinksStopped(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksInspectLinksStopped(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
 
 
-	dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
-	dockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
-	dockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
+	cli.DockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top")
+	cli.DockerCmd(c, "run", "-d", "--name", "container2", "busybox", "top")
+	cli.DockerCmd(c, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "true")
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
 	links := inspectFieldJSON(c, "testinspectlink", "HostConfig.Links")
 
 
 	var result []string
 	var result []string
@@ -141,22 +140,20 @@ func (s *DockerCLILinksSuite) TestLinksInspectLinksStopped(c *testing.T) {
 
 
 func (s *DockerCLILinksSuite) TestLinksNotStartedParentNotFail(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksNotStartedParentNotFail(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
-	dockerCmd(c, "create", "--name=first", "busybox", "top")
-	dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top")
-	dockerCmd(c, "start", "first")
+	cli.DockerCmd(c, "create", "--name=first", "busybox", "top")
+	cli.DockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top")
+	cli.DockerCmd(c, "start", "first")
 }
 }
 
 
 func (s *DockerCLILinksSuite) TestLinksHostsFilesInject(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksHostsFilesInject(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, testEnv.IsLocalDaemon)
 	testRequires(c, testEnv.IsLocalDaemon)
 
 
-	out, _ := dockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top")
-	idOne := strings.TrimSpace(out)
-
-	out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top")
-	idTwo := strings.TrimSpace(out)
-
-	assert.Assert(c, waitRun(idTwo) == nil)
+	idOne := cli.DockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top").Stdout()
+	idOne = strings.TrimSpace(idOne)
+	idTwo := cli.DockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top").Stdout()
+	idTwo = strings.TrimSpace(idTwo)
+	cli.WaitRun(c, idTwo)
 
 
 	readContainerFileWithExec(c, idOne, "/etc/hosts")
 	readContainerFileWithExec(c, idOne, "/etc/hosts")
 	contentTwo := readContainerFileWithExec(c, idTwo, "/etc/hosts")
 	contentTwo := readContainerFileWithExec(c, idTwo, "/etc/hosts")
@@ -167,9 +164,9 @@ func (s *DockerCLILinksSuite) TestLinksHostsFilesInject(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, testEnv.IsLocalDaemon)
 	testRequires(c, testEnv.IsLocalDaemon)
-	dockerCmd(c, "run", "-d", "--name", "one", "busybox", "top")
-	out, _ := dockerCmd(c, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top")
-	id := strings.TrimSpace(out)
+	cli.DockerCmd(c, "run", "-d", "--name", "one", "busybox", "top")
+	id := cli.DockerCmd(c, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top").Stdout()
+	id = strings.TrimSpace(id)
 
 
 	realIP := inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
 	realIP := inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
 	content := readContainerFileWithExec(c, id, "/etc/hosts")
 	content := readContainerFileWithExec(c, id, "/etc/hosts")
@@ -186,7 +183,7 @@ func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
 	ip = getIP(content, "onetwo")
 	ip = getIP(content, "onetwo")
 	assert.Check(c, is.Equal(ip, realIP))
 	assert.Check(c, is.Equal(ip, realIP))
 
 
-	dockerCmd(c, "restart", "one")
+	cli.DockerCmd(c, "restart", "one")
 	realIP = inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
 	realIP = inspectField(c, "one", "NetworkSettings.Networks.bridge.IPAddress")
 
 
 	content = readContainerFileWithExec(c, id, "/etc/hosts")
 	content = readContainerFileWithExec(c, id, "/etc/hosts")
@@ -199,8 +196,8 @@ func (s *DockerCLILinksSuite) TestLinksUpdateOnRestart(c *testing.T) {
 
 
 func (s *DockerCLILinksSuite) TestLinksEnvs(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksEnvs(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
-	dockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
-	out, _ := dockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env")
+	cli.DockerCmd(c, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top")
+	out := cli.DockerCmd(c, "run", "--name=second", "--link=first:first", "busybox", "env").Stdout()
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e1=\n"))
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e1=\n"))
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e2=v2"))
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e2=v2"))
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e3=v3=v3"))
 	assert.Assert(c, is.Contains(out, "FIRST_ENV_e3=v3=v3"))
@@ -208,15 +205,13 @@ func (s *DockerCLILinksSuite) TestLinksEnvs(c *testing.T) {
 
 
 func (s *DockerCLILinksSuite) TestLinkShortDefinition(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinkShortDefinition(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
-	out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top")
-
-	cid := strings.TrimSpace(out)
-	assert.Assert(c, waitRun(cid) == nil)
-
-	out, _ = dockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top")
+	cid := cli.DockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top").Stdout()
+	cid = strings.TrimSpace(cid)
+	cli.WaitRun(c, cid)
 
 
-	cid2 := strings.TrimSpace(out)
-	assert.Assert(c, waitRun(cid2) == nil)
+	cid2 := cli.DockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top").Stdout()
+	cid2 = strings.TrimSpace(cid2)
+	cli.WaitRun(c, cid2)
 
 
 	links := inspectFieldJSON(c, cid2, "HostConfig.Links")
 	links := inspectFieldJSON(c, cid2, "HostConfig.Links")
 	assert.Equal(c, links, `["/shortlinkdef:/link2/shortlinkdef"]`)
 	assert.Equal(c, links, `["/shortlinkdef:/link2/shortlinkdef"]`)
@@ -224,7 +219,7 @@ func (s *DockerCLILinksSuite) TestLinkShortDefinition(c *testing.T) {
 
 
 func (s *DockerCLILinksSuite) TestLinksNetworkHostContainer(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksNetworkHostContainer(c *testing.T) {
 	testRequires(c, DaemonIsLinux, NotUserNamespace)
 	testRequires(c, DaemonIsLinux, NotUserNamespace)
-	dockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")
+	cli.DockerCmd(c, "run", "-d", "--net", "host", "--name", "host_container", "busybox", "top")
 	out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")
 	out, _, err := dockerCmdWithError("run", "--name", "should_fail", "--link", "host_container:tester", "busybox", "true")
 
 
 	// Running container linking to a container with --net host should have failed
 	// Running container linking to a container with --net host should have failed
@@ -235,14 +230,14 @@ func (s *DockerCLILinksSuite) TestLinksNetworkHostContainer(c *testing.T) {
 
 
 func (s *DockerCLILinksSuite) TestLinksEtcHostsRegularFile(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksEtcHostsRegularFile(c *testing.T) {
 	testRequires(c, DaemonIsLinux, NotUserNamespace)
 	testRequires(c, DaemonIsLinux, NotUserNamespace)
-	out, _ := dockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts")
+	out := cli.DockerCmd(c, "run", "--net=host", "busybox", "ls", "-la", "/etc/hosts").Stdout()
 	// /etc/hosts should be a regular file
 	// /etc/hosts should be a regular file
 	assert.Assert(c, is.Regexp("^-.+\n$", out))
 	assert.Assert(c, is.Regexp("^-.+\n$", out))
 }
 }
 
 
 func (s *DockerCLILinksSuite) TestLinksMultipleWithSameName(c *testing.T) {
 func (s *DockerCLILinksSuite) TestLinksMultipleWithSameName(c *testing.T) {
 	testRequires(c, DaemonIsLinux)
 	testRequires(c, DaemonIsLinux)
-	dockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top")
-	dockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top")
-	dockerCmd(c, "run", "--link", "upstream-a:upstream", "--link", "upstream-b:upstream", "busybox", "sh", "-c", "ping -c 1 upstream")
+	cli.DockerCmd(c, "run", "-d", "--name=upstream-a", "busybox", "top")
+	cli.DockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top")
+	cli.DockerCmd(c, "run", "--link", "upstream-a:upstream", "--link", "upstream-b:upstream", "busybox", "sh", "-c", "ping -c 1 upstream")
 }
 }