1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

integcli: add tests for build --rm

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack 2014-05-19 21:21:25 +03:00
parent b60d647172
commit a691fcb277
3 changed files with 90 additions and 0 deletions

View file

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

View file

@ -0,0 +1 @@
bar

View file

@ -234,6 +234,91 @@ func TestBuildForceRm(t *testing.T) {
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: TestADDCacheInvalidation