Rewrite TestBuildRm to not use fixtures

Signed-off-by: Alexandr Morozov <lk4d4@docker.com>
This commit is contained in:
Alexandr Morozov 2014-09-24 13:15:55 +04:00
parent ab4738b49f
commit 52cf331206
3 changed files with 16 additions and 17 deletions

View File

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

View File

@ -1 +0,0 @@
bar

View File

@ -633,17 +633,23 @@ func TestBuildForceRm(t *testing.T) {
} }
func TestBuildRm(t *testing.T) { func TestBuildRm(t *testing.T) {
name := "testbuildrm"
defer deleteImages(name)
ctx, err := fakeContext("FROM scratch\nADD foo /\nADD foo /", map[string]string{"foo": "bar"})
if err != nil {
t.Fatal(err)
}
defer ctx.Close()
{ {
containerCountBefore, err := getContainerCount() containerCountBefore, err := getContainerCount()
if err != nil { if err != nil {
t.Fatalf("failed to get the container count: %s", err) t.Fatalf("failed to get the container count: %s", err)
} }
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") out, exitCode, err := dockerCmdInDir(t, ctx.Dir, "build", "--rm", "-t", name, ".")
_, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "--rm", "-t", "testbuildrm", ".")
if err != nil || exitCode != 0 { if err != nil || exitCode != 0 {
t.Fatal("failed to build the image") t.Fatal("failed to build the image", out)
} }
containerCountAfter, err := getContainerCount() containerCountAfter, err := getContainerCount()
@ -654,7 +660,7 @@ func TestBuildRm(t *testing.T) {
if containerCountBefore != containerCountAfter { if containerCountBefore != containerCountAfter {
t.Fatalf("-rm shouldn't have left containers behind") t.Fatalf("-rm shouldn't have left containers behind")
} }
deleteImages("testbuildrm") deleteImages(name)
} }
{ {
@ -663,11 +669,10 @@ func TestBuildRm(t *testing.T) {
t.Fatalf("failed to get the container count: %s", err) t.Fatalf("failed to get the container count: %s", err)
} }
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") out, exitCode, err := dockerCmdInDir(t, ctx.Dir, "build", "-t", name, ".")
_, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testbuildrm", ".")
if err != nil || exitCode != 0 { if err != nil || exitCode != 0 {
t.Fatal("failed to build the image") t.Fatal("failed to build the image", out)
} }
containerCountAfter, err := getContainerCount() containerCountAfter, err := getContainerCount()
@ -678,7 +683,7 @@ func TestBuildRm(t *testing.T) {
if containerCountBefore != containerCountAfter { if containerCountBefore != containerCountAfter {
t.Fatalf("--rm shouldn't have left containers behind") t.Fatalf("--rm shouldn't have left containers behind")
} }
deleteImages("testbuildrm") deleteImages(name)
} }
{ {
@ -687,11 +692,10 @@ func TestBuildRm(t *testing.T) {
t.Fatalf("failed to get the container count: %s", err) t.Fatalf("failed to get the container count: %s", err)
} }
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestBuildRm") out, exitCode, err := dockerCmdInDir(t, ctx.Dir, "build", "--rm=false", "-t", name, ".")
_, exitCode, err := dockerCmdInDir(t, buildDirectory, "build", "--rm=false", "-t", "testbuildrm", ".")
if err != nil || exitCode != 0 { if err != nil || exitCode != 0 {
t.Fatal("failed to build the image") t.Fatal("failed to build the image", out)
} }
containerCountAfter, err := getContainerCount() containerCountAfter, err := getContainerCount()
@ -703,7 +707,7 @@ func TestBuildRm(t *testing.T) {
t.Fatalf("--rm=false should have left containers behind") t.Fatalf("--rm=false should have left containers behind")
} }
deleteAllContainers() deleteAllContainers()
deleteImages("testbuildrm") deleteImages(name)
} }