diff options
| author | Lei <leijitang@huawei.com> | 2015-07-20 14:44:22 +0800 |
|---|---|---|
| committer | Lei <leijitang@huawei.com> | 2015-07-20 14:44:22 +0800 |
| commit | eef6eda7d295a7577bdbe2e4630ce3350c6d7701 (patch) | |
| tree | cd9dfe7d527fc4c9082d2ee9181e0597dd575ffb /integration-cli/docker_cli_links_test.go | |
| parent | c6cde91b7d2cb3671dc55cafc5ab693f9cb17cc8 (diff) | |
| download | docker-eef6eda7d295a7577bdbe2e4630ce3350c6d7701.tar.gz | |
Recfactor: Use dockerCmd when possible in integration-cli tests
Part of #14603
integration-cli/docker_cli_links_test.go (coolljt0725)
integration-cli/docker_cli_links_unix_test.go (coolljt0725)
integration-cli/docker_cli_logs_test.go (coolljt0725)
integration-cli/docker_cli_nat_test.go (coolljt0725)
integration-cli/docker_cli_network_test.go (coolljt0725)
integration-cli/docker_cli_stats_test.go (coolljt0725)
integration-cli/docker_cli_tag_test.go (coolljt0725)
integration-cli/docker_cli_top_test.go (coolljt0725)
integration-cli/docker_cli_version_test.go (coolljt0725)
integration-cli/docker_cli_wait_test.go (coolljt0725
Signed-off-by: Lei Jitang <leijitang@huawei.com>
Diffstat (limited to 'integration-cli/docker_cli_links_test.go')
| -rw-r--r-- | integration-cli/docker_cli_links_test.go | 90 |
1 files changed, 20 insertions, 70 deletions
diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index c030226dbc..568f20a940 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -2,18 +2,16 @@ package main import ( "fmt" - "os/exec" + "github.com/go-check/check" "reflect" "regexp" "strings" "time" - - "github.com/go-check/check" ) func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") - exitCode, err := runCommand(runCmd) + + _, exitCode, err := dockerCmdWithError(c, "run", "--rm", "busybox", "sh", "-c", "ping -c 1 alias1 -W 1 && ping -c 1 alias2 -W 1") if exitCode == 0 { c.Fatal("run ping did not fail") @@ -26,8 +24,7 @@ func (s *DockerSuite) TestLinksPingUnlinkedContainers(c *check.C) { // Test for appropriate error when calling --link with an invalid target container func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "--link", "bogus:alias", "busybox", "true") - out, _, err := runCommandWithOutput(runCmd) + out, _, err := dockerCmdWithError(c, "run", "--link", "bogus:alias", "busybox", "true") if err == nil { c.Fatal("an invalid container target should produce an error") @@ -40,14 +37,8 @@ func (s *DockerSuite) TestLinksInvalidContainerTarget(c *check.C) { func (s *DockerSuite) TestLinksPingLinkedContainers(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top") - if _, err := runCommand(runCmd); err != nil { - c.Fatal(err) - } - runCmd = exec.Command(dockerBinary, "run", "-d", "--name", "container2", "--hostname", "wilma", "busybox", "top") - if _, err := runCommand(runCmd); err != nil { - c.Fatal(err) - } + dockerCmd(c, "run", "-d", "--name", "container1", "--hostname", "fred", "busybox", "top") + dockerCmd(c, "run", "-d", "--name", "container2", "--hostname", "wilma", "busybox", "top") runArgs := []string{"run", "--rm", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sh", "-c"} pingCmd := "ping -c 1 %s -W 1 && ping -c 1 %s -W 1" @@ -131,38 +122,20 @@ func (s *DockerSuite) TestLinksInspectLinksStopped(c *check.C) { } func (s *DockerSuite) TestLinksNotStartedParentNotFail(c *check.C) { - runCmd := exec.Command(dockerBinary, "create", "--name=first", "busybox", "top") - out, _, _, err := runCommandWithStdoutStderr(runCmd) - if err != nil { - c.Fatal(out, err) - } - runCmd = exec.Command(dockerBinary, "create", "--name=second", "--link=first:first", "busybox", "top") - out, _, _, err = runCommandWithStdoutStderr(runCmd) - if err != nil { - c.Fatal(out, err) - } - runCmd = exec.Command(dockerBinary, "start", "first") - out, _, _, err = runCommandWithStdoutStderr(runCmd) - if err != nil { - c.Fatal(out, err) - } + + dockerCmd(c, "create", "--name=first", "busybox", "top") + dockerCmd(c, "create", "--name=second", "--link=first:first", "busybox", "top") + dockerCmd(c, "start", "first") + } func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) { testRequires(c, SameHostDaemon, ExecSupport) - out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "one", "busybox", "top")) - if err != nil { - c.Fatal(err, out) - } - + out, _ := dockerCmd(c, "run", "-itd", "--name", "one", "busybox", "top") idOne := strings.TrimSpace(out) - out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top")) - if err != nil { - c.Fatal(err, out) - } - + out, _ = dockerCmd(c, "run", "-itd", "--name", "two", "--link", "one:onetwo", "busybox", "top") idTwo := strings.TrimSpace(out) time.Sleep(1 * time.Second) @@ -185,14 +158,8 @@ func (s *DockerSuite) TestLinksHostsFilesInject(c *check.C) { func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { testRequires(c, SameHostDaemon, ExecSupport) - - if out, err := exec.Command(dockerBinary, "run", "-d", "--name", "one", "busybox", "top").CombinedOutput(); err != nil { - c.Fatal(err, string(out)) - } - out, err := exec.Command(dockerBinary, "run", "-d", "--name", "two", "--link", "one:onetwo", "--link", "one:one", "busybox", "top").CombinedOutput() - if err != nil { - c.Fatal(err, string(out)) - } + 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(string(out)) realIP, err := inspectField("one", "NetworkSettings.IPAddress") @@ -217,9 +184,7 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { if ip := getIP(content, "onetwo"); ip != realIP { c.Fatalf("For 'onetwo' alias expected IP: %s, got: %s", realIP, ip) } - if out, err := exec.Command(dockerBinary, "restart", "one").CombinedOutput(); err != nil { - c.Fatal(err, string(out)) - } + dockerCmd(c, "restart", "one") realIP, err = inspectField("one", "NetworkSettings.IPAddress") if err != nil { c.Fatal(err) @@ -237,19 +202,8 @@ func (s *DockerSuite) TestLinksUpdateOnRestart(c *check.C) { } func (s *DockerSuite) TestLinksEnvs(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "-d", "-e", "e1=", "-e", "e2=v2", "-e", "e3=v3=v3", "--name=first", "busybox", "top") - out, _, _, err := runCommandWithStdoutStderr(runCmd) - if err != nil { - c.Fatalf("Run of first failed: %s\n%s", out, err) - } - - runCmd = exec.Command(dockerBinary, "run", "--name=second", "--link=first:first", "busybox", "env") - - out, stde, rc, err := runCommandWithStdoutStderr(runCmd) - if err != nil || rc != 0 { - c.Fatalf("run of 2nd failed: rc: %d, out: %s\n err: %s", rc, out, stde) - } - + 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") if !strings.Contains(out, "FIRST_ENV_e1=\n") || !strings.Contains(out, "FIRST_ENV_e2=v2") || !strings.Contains(out, "FIRST_ENV_e3=v3=v3") { @@ -258,16 +212,12 @@ func (s *DockerSuite) TestLinksEnvs(c *check.C) { } func (s *DockerSuite) TestLinkShortDefinition(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "shortlinkdef", "busybox", "top") - out, _, err := runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) + out, _ := dockerCmd(c, "run", "-d", "--name", "shortlinkdef", "busybox", "top") cid := strings.TrimSpace(out) c.Assert(waitRun(cid), check.IsNil) - runCmd = exec.Command(dockerBinary, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top") - out, _, err = runCommandWithOutput(runCmd) - c.Assert(err, check.IsNil) + out, _ = dockerCmd(c, "run", "-d", "--name", "link2", "--link", "shortlinkdef", "busybox", "top") cid2 := strings.TrimSpace(out) c.Assert(waitRun(cid2), check.IsNil) |
