Browse code

Move TestRunCidFileCleanupIfEmpty to integration-cli

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>

Alexandr Morozov authored on 2014/09/02 00:55:39
Showing 2 changed files
... ...
@@ -1772,3 +1772,26 @@ func TestHostsLinkedContainerUpdate(t *testing.T) {
1772 1772
 
1773 1773
 	logDone("run - /etc/hosts updated in parent when restart")
1774 1774
 }
1775
+
1776
+// Ensure that CIDFile gets deleted if it's empty
1777
+// Perform this test by making `docker run` fail
1778
+func TestRunCidFileCleanupIfEmpty(t *testing.T) {
1779
+	tmpDir, err := ioutil.TempDir("", "TestRunCidFile")
1780
+	if err != nil {
1781
+		t.Fatal(err)
1782
+	}
1783
+	defer os.RemoveAll(tmpDir)
1784
+	tmpCidFile := path.Join(tmpDir, "cid")
1785
+	cmd := exec.Command(dockerBinary, "run", "--cidfile", tmpCidFile, "scratch")
1786
+	out, _, err := runCommandWithOutput(cmd)
1787
+	t.Log(out)
1788
+	if err == nil {
1789
+		t.Fatal("Run without command must fail")
1790
+	}
1791
+
1792
+	if _, err := os.Stat(tmpCidFile); err == nil {
1793
+		t.Fatalf("empty CIDFile '%s' should've been deleted", tmpCidFile)
1794
+	}
1795
+	deleteAllContainers()
1796
+	logDone("run - cleanup empty cidfile on fail")
1797
+}
... ...
@@ -583,32 +583,3 @@ func TestRunCidFileCheckIDLength(t *testing.T) {
583 583
 	})
584 584
 
585 585
 }
586
-
587
-// Ensure that CIDFile gets deleted if it's empty
588
-// Perform this test by making `docker run` fail
589
-func TestRunCidFileCleanupIfEmpty(t *testing.T) {
590
-	tmpDir, err := ioutil.TempDir("", "TestRunCidFile")
591
-	if err != nil {
592
-		t.Fatal(err)
593
-	}
594
-	tmpCidFile := path.Join(tmpDir, "cid")
595
-
596
-	cli := client.NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr, nil)
597
-	defer cleanup(globalEngine, t)
598
-
599
-	c := make(chan struct{})
600
-	go func() {
601
-		defer close(c)
602
-		if err := cli.CmdRun("--cidfile", tmpCidFile, unitTestImageID); err == nil {
603
-			t.Fatal("running without a command should haveve failed")
604
-		}
605
-		if _, err := os.Stat(tmpCidFile); err == nil {
606
-			t.Fatalf("empty CIDFile '%s' should've been deleted", tmpCidFile)
607
-		}
608
-	}()
609
-	defer os.RemoveAll(tmpDir)
610
-
611
-	setTimeout(t, "CmdRun timed out", 5*time.Second, func() {
612
-		<-c
613
-	})
614
-}