Browse code

integcli: test container removal for failed builds

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/05/20 01:46:25
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,3 @@
0
+FROM busybox
1
+RUN true
2
+RUN thiswillfail
... ...
@@ -207,6 +207,33 @@ func TestBuildWithInaccessibleFilesInContext(t *testing.T) {
207 207
 	logDone("build - ADD from context with accessible links must work")
208 208
 }
209 209
 
210
+func TestBuildForceRm(t *testing.T) {
211
+	containerCountBefore, err := getContainerCount()
212
+	if err != nil {
213
+		t.Fatalf("failed to get the container count: %s", err)
214
+	}
215
+
216
+	buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildForceRm")
217
+	buildCmd := exec.Command(dockerBinary, "build", "--force-rm", ".")
218
+	buildCmd.Dir = buildDirectory
219
+	_, exitCode, err := runCommandWithOutput(buildCmd)
220
+
221
+	if err == nil || exitCode == 0 {
222
+		t.Fatal("failed to build the image")
223
+	}
224
+
225
+	containerCountAfter, err := getContainerCount()
226
+	if err != nil {
227
+		t.Fatalf("failed to get the container count: %s", err)
228
+	}
229
+
230
+	if containerCountBefore != containerCountAfter {
231
+		t.Fatalf("--force-rm shouldn't have left containers behind")
232
+	}
233
+
234
+	logDone("build - ensure --force-rm doesn't leave containers behind")
235
+}
236
+
210 237
 // TODO: TestCaching
211 238
 
212 239
 // TODO: TestADDCacheInvalidation