Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -234,6 +234,91 @@ func TestBuildForceRm(t *testing.T) {
|
| 234 | 234 |
logDone("build - ensure --force-rm doesn't leave containers behind")
|
| 235 | 235 |
} |
| 236 | 236 |
|
| 237 |
+func TestBuildRm(t *testing.T) {
|
|
| 238 |
+ {
|
|
| 239 |
+ containerCountBefore, err := getContainerCount() |
|
| 240 |
+ if err != nil {
|
|
| 241 |
+ t.Fatalf("failed to get the container count: %s", err)
|
|
| 242 |
+ } |
|
| 243 |
+ |
|
| 244 |
+ buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") |
|
| 245 |
+ buildCmd := exec.Command(dockerBinary, "build", "--rm", "-t", "testbuildrm", ".") |
|
| 246 |
+ buildCmd.Dir = buildDirectory |
|
| 247 |
+ _, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 248 |
+ |
|
| 249 |
+ if err != nil || exitCode != 0 {
|
|
| 250 |
+ t.Fatal("failed to build the image")
|
|
| 251 |
+ } |
|
| 252 |
+ |
|
| 253 |
+ containerCountAfter, err := getContainerCount() |
|
| 254 |
+ if err != nil {
|
|
| 255 |
+ t.Fatalf("failed to get the container count: %s", err)
|
|
| 256 |
+ } |
|
| 257 |
+ |
|
| 258 |
+ if containerCountBefore != containerCountAfter {
|
|
| 259 |
+ t.Fatalf("-rm shouldn't have left containers behind")
|
|
| 260 |
+ } |
|
| 261 |
+ deleteImages("testbuildrm")
|
|
| 262 |
+ } |
|
| 263 |
+ |
|
| 264 |
+ {
|
|
| 265 |
+ containerCountBefore, err := getContainerCount() |
|
| 266 |
+ if err != nil {
|
|
| 267 |
+ t.Fatalf("failed to get the container count: %s", err)
|
|
| 268 |
+ } |
|
| 269 |
+ |
|
| 270 |
+ buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") |
|
| 271 |
+ buildCmd := exec.Command(dockerBinary, "build", "-t", "testbuildrm", ".") |
|
| 272 |
+ buildCmd.Dir = buildDirectory |
|
| 273 |
+ _, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 274 |
+ |
|
| 275 |
+ if err != nil || exitCode != 0 {
|
|
| 276 |
+ t.Fatal("failed to build the image")
|
|
| 277 |
+ } |
|
| 278 |
+ |
|
| 279 |
+ containerCountAfter, err := getContainerCount() |
|
| 280 |
+ if err != nil {
|
|
| 281 |
+ t.Fatalf("failed to get the container count: %s", err)
|
|
| 282 |
+ } |
|
| 283 |
+ |
|
| 284 |
+ if containerCountBefore != containerCountAfter {
|
|
| 285 |
+ t.Fatalf("--rm shouldn't have left containers behind")
|
|
| 286 |
+ } |
|
| 287 |
+ deleteImages("testbuildrm")
|
|
| 288 |
+ } |
|
| 289 |
+ |
|
| 290 |
+ {
|
|
| 291 |
+ containerCountBefore, err := getContainerCount() |
|
| 292 |
+ if err != nil {
|
|
| 293 |
+ t.Fatalf("failed to get the container count: %s", err)
|
|
| 294 |
+ } |
|
| 295 |
+ |
|
| 296 |
+ buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") |
|
| 297 |
+ buildCmd := exec.Command(dockerBinary, "build", "--rm=false", "-t", "testbuildrm", ".") |
|
| 298 |
+ buildCmd.Dir = buildDirectory |
|
| 299 |
+ _, exitCode, err := runCommandWithOutput(buildCmd) |
|
| 300 |
+ |
|
| 301 |
+ if err != nil || exitCode != 0 {
|
|
| 302 |
+ t.Fatal("failed to build the image")
|
|
| 303 |
+ } |
|
| 304 |
+ |
|
| 305 |
+ containerCountAfter, err := getContainerCount() |
|
| 306 |
+ if err != nil {
|
|
| 307 |
+ t.Fatalf("failed to get the container count: %s", err)
|
|
| 308 |
+ } |
|
| 309 |
+ |
|
| 310 |
+ if containerCountBefore == containerCountAfter {
|
|
| 311 |
+ t.Fatalf("--rm=false should have left containers behind")
|
|
| 312 |
+ } |
|
| 313 |
+ deleteAllContainers() |
|
| 314 |
+ deleteImages("testbuildrm")
|
|
| 315 |
+ |
|
| 316 |
+ } |
|
| 317 |
+ |
|
| 318 |
+ logDone("build - ensure --rm doesn't leave containers behind and that --rm=true is the default")
|
|
| 319 |
+ logDone("build - ensure --rm=false overrides the default")
|
|
| 320 |
+} |
|
| 321 |
+ |
|
| 237 | 322 |
// TODO: TestCaching |
| 238 | 323 |
|
| 239 | 324 |
// TODO: TestADDCacheInvalidation |