From 8892320835ad2b21b0efd4848d2af0d8a791a8e9 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Mon, 1 Sep 2014 19:55:39 +0400 Subject: [PATCH] Move TestRunCidFileCleanupIfEmpty to integration-cli Signed-off-by: Alexandr Morozov --- integration-cli/docker_cli_run_test.go | 23 ++++++++++++++++++++ integration/commands_test.go | 29 -------------------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index b50d580163..189ac917ba 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -1772,3 +1772,26 @@ func TestHostsLinkedContainerUpdate(t *testing.T) { logDone("run - /etc/hosts updated in parent when restart") } + +// Ensure that CIDFile gets deleted if it's empty +// Perform this test by making `docker run` fail +func TestRunCidFileCleanupIfEmpty(t *testing.T) { + tmpDir, err := ioutil.TempDir("", "TestRunCidFile") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpDir) + tmpCidFile := path.Join(tmpDir, "cid") + cmd := exec.Command(dockerBinary, "run", "--cidfile", tmpCidFile, "scratch") + out, _, err := runCommandWithOutput(cmd) + t.Log(out) + if err == nil { + t.Fatal("Run without command must fail") + } + + if _, err := os.Stat(tmpCidFile); err == nil { + t.Fatalf("empty CIDFile '%s' should've been deleted", tmpCidFile) + } + deleteAllContainers() + logDone("run - cleanup empty cidfile on fail") +} diff --git a/integration/commands_test.go b/integration/commands_test.go index 10735750dc..60deac5b62 100644 --- a/integration/commands_test.go +++ b/integration/commands_test.go @@ -583,32 +583,3 @@ func TestRunCidFileCheckIDLength(t *testing.T) { }) } - -// Ensure that CIDFile gets deleted if it's empty -// Perform this test by making `docker run` fail -func TestRunCidFileCleanupIfEmpty(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "TestRunCidFile") - if err != nil { - t.Fatal(err) - } - tmpCidFile := path.Join(tmpDir, "cid") - - cli := client.NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr, nil) - defer cleanup(globalEngine, t) - - c := make(chan struct{}) - go func() { - defer close(c) - if err := cli.CmdRun("--cidfile", tmpCidFile, unitTestImageID); err == nil { - t.Fatal("running without a command should haveve failed") - } - if _, err := os.Stat(tmpCidFile); err == nil { - t.Fatalf("empty CIDFile '%s' should've been deleted", tmpCidFile) - } - }() - defer os.RemoveAll(tmpDir) - - setTimeout(t, "CmdRun timed out", 5*time.Second, func() { - <-c - }) -}