Browse code

Rewrite TestContextTar tests to not use fixtures

Signed-off-by: Alexandr Morozov <lk4d4@docker.com>

Alexandr Morozov authored on 2014/09/24 21:55:52
Showing 3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,3 +0,0 @@
1
-FROM busybox
2
-ADD foo /foo
3
-CMD ["cat", "/foo"]
4 1
deleted file mode 100644
... ...
@@ -1 +0,0 @@
1
-foo
... ...
@@ -1414,20 +1414,31 @@ func TestBuildADDLocalAndRemoteFilesWithCache(t *testing.T) {
1414 1414
 }
1415 1415
 
1416 1416
 func testContextTar(t *testing.T, compression archive.Compression) {
1417
-	contextDirectory := filepath.Join(workingDirectory, "build_tests", "TestContextTar")
1418
-	context, err := archive.Tar(contextDirectory, compression)
1419
-
1417
+	ctx, err := fakeContext(
1418
+		`FROM busybox
1419
+ADD foo /foo
1420
+CMD ["cat", "/foo"]`,
1421
+		map[string]string{
1422
+			"foo": "bar",
1423
+		},
1424
+	)
1425
+	defer ctx.Close()
1426
+	if err != nil {
1427
+		t.Fatal(err)
1428
+	}
1429
+	context, err := archive.Tar(ctx.Dir, compression)
1420 1430
 	if err != nil {
1421 1431
 		t.Fatalf("failed to build context tar: %v", err)
1422 1432
 	}
1423
-	buildCmd := exec.Command(dockerBinary, "build", "-t", "contexttar", "-")
1433
+	name := "contexttar"
1434
+	buildCmd := exec.Command(dockerBinary, "build", "-t", name, "-")
1435
+	defer deleteImages(name)
1424 1436
 	buildCmd.Stdin = context
1425 1437
 
1426 1438
 	out, exitCode, err := runCommandWithOutput(buildCmd)
1427 1439
 	if err != nil || exitCode != 0 {
1428 1440
 		t.Fatalf("build failed to complete: %v %v", out, err)
1429 1441
 	}
1430
-	deleteImages("contexttar")
1431 1442
 	logDone(fmt.Sprintf("build - build an image with a context tar, compression: %v", compression))
1432 1443
 }
1433 1444