Browse Source

integcli: add tests for build --rm

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
unclejack 11 years ago
parent
commit
a691fcb277

+ 4 - 0
integration-cli/build_tests/TestBuildRm/Dockerfile

@@ -0,0 +1,4 @@
+FROM busybox
+ADD foo /
+ADD foo /
+

+ 1 - 0
integration-cli/build_tests/TestBuildRm/foo

@@ -0,0 +1 @@
+bar

+ 85 - 0
integration-cli/docker_cli_build_test.go

@@ -234,6 +234,91 @@ func TestBuildForceRm(t *testing.T) {
 	logDone("build - ensure --force-rm doesn't leave containers behind")
 	logDone("build - ensure --force-rm doesn't leave containers behind")
 }
 }
 
 
+func TestBuildRm(t *testing.T) {
+	{
+		containerCountBefore, err := getContainerCount()
+		if err != nil {
+			t.Fatalf("failed to get the container count: %s", err)
+		}
+
+		buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm")
+		buildCmd := exec.Command(dockerBinary, "build", "--rm", "-t", "testbuildrm", ".")
+		buildCmd.Dir = buildDirectory
+		_, exitCode, err := runCommandWithOutput(buildCmd)
+
+		if err != nil || exitCode != 0 {
+			t.Fatal("failed to build the image")
+		}
+
+		containerCountAfter, err := getContainerCount()
+		if err != nil {
+			t.Fatalf("failed to get the container count: %s", err)
+		}
+
+		if containerCountBefore != containerCountAfter {
+			t.Fatalf("-rm shouldn't have left containers behind")
+		}
+		deleteImages("testbuildrm")
+	}
+
+	{
+		containerCountBefore, err := getContainerCount()
+		if err != nil {
+			t.Fatalf("failed to get the container count: %s", err)
+		}
+
+		buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm")
+		buildCmd := exec.Command(dockerBinary, "build", "-t", "testbuildrm", ".")
+		buildCmd.Dir = buildDirectory
+		_, exitCode, err := runCommandWithOutput(buildCmd)
+
+		if err != nil || exitCode != 0 {
+			t.Fatal("failed to build the image")
+		}
+
+		containerCountAfter, err := getContainerCount()
+		if err != nil {
+			t.Fatalf("failed to get the container count: %s", err)
+		}
+
+		if containerCountBefore != containerCountAfter {
+			t.Fatalf("--rm shouldn't have left containers behind")
+		}
+		deleteImages("testbuildrm")
+	}
+
+	{
+		containerCountBefore, err := getContainerCount()
+		if err != nil {
+			t.Fatalf("failed to get the container count: %s", err)
+		}
+
+		buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm")
+		buildCmd := exec.Command(dockerBinary, "build", "--rm=false", "-t", "testbuildrm", ".")
+		buildCmd.Dir = buildDirectory
+		_, exitCode, err := runCommandWithOutput(buildCmd)
+
+		if err != nil || exitCode != 0 {
+			t.Fatal("failed to build the image")
+		}
+
+		containerCountAfter, err := getContainerCount()
+		if err != nil {
+			t.Fatalf("failed to get the container count: %s", err)
+		}
+
+		if containerCountBefore == containerCountAfter {
+			t.Fatalf("--rm=false should have left containers behind")
+		}
+		deleteAllContainers()
+		deleteImages("testbuildrm")
+
+	}
+
+	logDone("build - ensure --rm doesn't leave containers behind and that --rm=true is the default")
+	logDone("build - ensure --rm=false overrides the default")
+}
+
 // TODO: TestCaching
 // TODO: TestCaching
 
 
 // TODO: TestADDCacheInvalidation
 // TODO: TestADDCacheInvalidation