From 43d1c2010125e3c1ef1013ee2e8b4d9371d70d77 Mon Sep 17 00:00:00 2001 From: Jessica Frazelle Date: Mon, 19 Jan 2015 12:11:19 -0800 Subject: [PATCH] Move links exec test & exec dir test. Docker-DCO-1.1-Signed-off-by: Jessica Frazelle (github: jfrazelle) --- integration-cli/docker_cli_exec_test.go | 133 +++++++++++++++++++++++ integration-cli/docker_cli_links_test.go | 32 ------ integration-cli/docker_cli_run_test.go | 100 ----------------- 3 files changed, 133 insertions(+), 132 deletions(-) diff --git a/integration-cli/docker_cli_exec_test.go b/integration-cli/docker_cli_exec_test.go index 0b98f804c3..85906a8ae0 100644 --- a/integration-cli/docker_cli_exec_test.go +++ b/integration-cli/docker_cli_exec_test.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "os/exec" + "path/filepath" "reflect" "sort" "strings" @@ -490,3 +491,135 @@ func TestInspectExecID(t *testing.T) { logDone("inspect - inspect a container with ExecIDs") } + +func TestLinksPingLinkedContainersOnRename(t *testing.T) { + var out string + out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") + idA := stripTrailingCharacters(out) + if idA == "" { + t.Fatal(out, "id should not be nil") + } + out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10") + idB := stripTrailingCharacters(out) + if idB == "" { + t.Fatal(out, "id should not be nil") + } + + execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") + out, _, err := runCommandWithOutput(execCmd) + if err != nil { + t.Fatal(out, err) + } + + dockerCmd(t, "rename", "container1", "container_new") + + execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") + out, _, err = runCommandWithOutput(execCmd) + if err != nil { + t.Fatal(out, err) + } + + deleteAllContainers() + + logDone("links - ping linked container upon rename") +} + +func TestRunExecDir(t *testing.T) { + cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") + out, _, err := runCommandWithOutput(cmd) + if err != nil { + t.Fatal(err, out) + } + id := strings.TrimSpace(out) + execDir := filepath.Join(execDriverPath, id) + stateFile := filepath.Join(execDir, "state.json") + contFile := filepath.Join(execDir, "container.json") + + { + fi, err := os.Stat(execDir) + if err != nil { + t.Fatal(err) + } + if !fi.IsDir() { + t.Fatalf("%q must be a directory", execDir) + } + fi, err = os.Stat(stateFile) + if err != nil { + t.Fatal(err) + } + fi, err = os.Stat(contFile) + if err != nil { + t.Fatal(err) + } + } + + stopCmd := exec.Command(dockerBinary, "stop", id) + out, _, err = runCommandWithOutput(stopCmd) + if err != nil { + t.Fatal(err, out) + } + { + fi, err := os.Stat(execDir) + if err != nil { + t.Fatal(err) + } + if !fi.IsDir() { + t.Fatalf("%q must be a directory", execDir) + } + fi, err = os.Stat(stateFile) + if err == nil { + t.Fatalf("Statefile %q is exists for stopped container!", stateFile) + } + if !os.IsNotExist(err) { + t.Fatalf("Error should be about non-existing, got %s", err) + } + fi, err = os.Stat(contFile) + if err == nil { + t.Fatalf("Container file %q is exists for stopped container!", contFile) + } + if !os.IsNotExist(err) { + t.Fatalf("Error should be about non-existing, got %s", err) + } + } + startCmd := exec.Command(dockerBinary, "start", id) + out, _, err = runCommandWithOutput(startCmd) + if err != nil { + t.Fatal(err, out) + } + { + fi, err := os.Stat(execDir) + if err != nil { + t.Fatal(err) + } + if !fi.IsDir() { + t.Fatalf("%q must be a directory", execDir) + } + fi, err = os.Stat(stateFile) + if err != nil { + t.Fatal(err) + } + fi, err = os.Stat(contFile) + if err != nil { + t.Fatal(err) + } + } + rmCmd := exec.Command(dockerBinary, "rm", "-f", id) + out, _, err = runCommandWithOutput(rmCmd) + if err != nil { + t.Fatal(err, out) + } + { + _, err := os.Stat(execDir) + if err == nil { + t.Fatal(err) + } + if err == nil { + t.Fatalf("Exec directory %q is exists for removed container!", execDir) + } + if !os.IsNotExist(err) { + t.Fatalf("Error should be about non-existing, got %s", err) + } + } + + logDone("run - check execdriver dir behavior") +} diff --git a/integration-cli/docker_cli_links_test.go b/integration-cli/docker_cli_links_test.go index fc99ec57fb..015db0f89f 100644 --- a/integration-cli/docker_cli_links_test.go +++ b/integration-cli/docker_cli_links_test.go @@ -92,38 +92,6 @@ func TestLinksPingLinkedContainersAfterRename(t *testing.T) { logDone("links - ping linked container after rename") } -func TestLinksPingLinkedContainersOnRename(t *testing.T) { - var out string - out, _, _ = dockerCmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10") - idA := stripTrailingCharacters(out) - if idA == "" { - t.Fatal(out, "id should not be nil") - } - out, _, _ = dockerCmd(t, "run", "-d", "--link", "container1:alias1", "--name", "container2", "busybox", "sleep", "10") - idB := stripTrailingCharacters(out) - if idB == "" { - t.Fatal(out, "id should not be nil") - } - - execCmd := exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") - out, _, err := runCommandWithOutput(execCmd) - if err != nil { - t.Fatal(out, err) - } - - dockerCmd(t, "rename", "container1", "container_new") - - execCmd = exec.Command(dockerBinary, "exec", "container2", "ping", "-c", "1", "alias1", "-W", "1") - out, _, err = runCommandWithOutput(execCmd) - if err != nil { - t.Fatal(out, err) - } - - deleteAllContainers() - - logDone("links - ping linked container upon rename") -} - func TestLinksIpTablesRulesWhenLinkAndUnlink(t *testing.T) { dockerCmd(t, "run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "sleep", "10") dockerCmd(t, "run", "-d", "--name", "parent", "--link", "child:http", "busybox", "sleep", "10") diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index 6da5b76565..a010c4e22a 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -2404,106 +2404,6 @@ func TestRunMountOrdering(t *testing.T) { logDone("run - volumes are mounted in the correct order") } -func TestRunExecDir(t *testing.T) { - cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top") - out, _, err := runCommandWithOutput(cmd) - if err != nil { - t.Fatal(err, out) - } - id := strings.TrimSpace(out) - execDir := filepath.Join(execDriverPath, id) - stateFile := filepath.Join(execDir, "state.json") - contFile := filepath.Join(execDir, "container.json") - - { - fi, err := os.Stat(execDir) - if err != nil { - t.Fatal(err) - } - if !fi.IsDir() { - t.Fatalf("%q must be a directory", execDir) - } - fi, err = os.Stat(stateFile) - if err != nil { - t.Fatal(err) - } - fi, err = os.Stat(contFile) - if err != nil { - t.Fatal(err) - } - } - - stopCmd := exec.Command(dockerBinary, "stop", id) - out, _, err = runCommandWithOutput(stopCmd) - if err != nil { - t.Fatal(err, out) - } - { - fi, err := os.Stat(execDir) - if err != nil { - t.Fatal(err) - } - if !fi.IsDir() { - t.Fatalf("%q must be a directory", execDir) - } - fi, err = os.Stat(stateFile) - if err == nil { - t.Fatalf("Statefile %q is exists for stopped container!", stateFile) - } - if !os.IsNotExist(err) { - t.Fatalf("Error should be about non-existing, got %s", err) - } - fi, err = os.Stat(contFile) - if err == nil { - t.Fatalf("Container file %q is exists for stopped container!", contFile) - } - if !os.IsNotExist(err) { - t.Fatalf("Error should be about non-existing, got %s", err) - } - } - startCmd := exec.Command(dockerBinary, "start", id) - out, _, err = runCommandWithOutput(startCmd) - if err != nil { - t.Fatal(err, out) - } - { - fi, err := os.Stat(execDir) - if err != nil { - t.Fatal(err) - } - if !fi.IsDir() { - t.Fatalf("%q must be a directory", execDir) - } - fi, err = os.Stat(stateFile) - if err != nil { - t.Fatal(err) - } - fi, err = os.Stat(contFile) - if err != nil { - t.Fatal(err) - } - } - rmCmd := exec.Command(dockerBinary, "rm", "-f", id) - out, _, err = runCommandWithOutput(rmCmd) - if err != nil { - t.Fatal(err, out) - } - { - _, err := os.Stat(execDir) - if err == nil { - t.Fatal(err) - } - if err == nil { - t.Fatalf("Exec directory %q is exists for removed container!", execDir) - } - if !os.IsNotExist(err) { - t.Fatalf("Error should be about non-existing, got %s", err) - } - } - - logDone("run - check execdriver dir behavior") -} - // Regression test for https://github.com/docker/docker/issues/8259 func TestRunReuseBindVolumeThatIsSymlink(t *testing.T) { tmpDir, err := ioutil.TempDir(os.TempDir(), "testlink")