Browse code

Rewrite TestBuildCopySingleFileToWorkdir to not use fixtures

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

Alexandr Morozov authored on 2014/10/15 02:12:11
Showing 2 changed files
1 1
deleted file mode 100644
... ...
@@ -1,2 +0,0 @@
1
-FROM busybox
2
-COPY test_file .
... ...
@@ -661,28 +661,28 @@ RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
661 661
 
662 662
 // Issue #3960: "ADD src ." hangs - adapted for COPY
663 663
 func TestBuildCopySingleFileToWorkdir(t *testing.T) {
664
-	testDirName := "SingleFileToWorkdir"
665
-	sourceDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy", testDirName)
666
-	buildDirectory, err := ioutil.TempDir("", "test-build-add")
667
-	defer os.RemoveAll(buildDirectory)
668
-
669
-	err = copyWithCP(sourceDirectory, buildDirectory)
670
-	if err != nil {
671
-		t.Fatalf("failed to copy files to temporary directory: %s", err)
672
-	}
673
-
674
-	buildDirectory = filepath.Join(buildDirectory, testDirName)
675
-	f, err := os.OpenFile(filepath.Join(buildDirectory, "test_file"), os.O_CREATE, 0644)
664
+	name := "testcopysinglefiletoworkdir"
665
+	defer deleteImages(name)
666
+	ctx, err := fakeContext(`FROM busybox
667
+COPY test_file .`,
668
+		map[string]string{
669
+			"test_file": "test1",
670
+		})
676 671
 	if err != nil {
677 672
 		t.Fatal(err)
678 673
 	}
679
-	f.Close()
680
-	if out, _, err := dockerCmdInDirWithTimeout(5*time.Second, buildDirectory, "build", "-t", "testcopyimg", "."); err != nil {
681
-		t.Fatalf("build failed to complete: %s, %v", out, err)
674
+	done := make(chan struct{})
675
+	go func() {
676
+		if _, err := buildImageFromContext(name, ctx, true); err != nil {
677
+			t.Fatal(err)
678
+		}
679
+		close(done)
680
+	}()
681
+	select {
682
+	case <-time.After(5 * time.Second):
683
+		t.Fatal("Build with adding to workdir timed out")
684
+	case <-done:
682 685
 	}
683
-
684
-	deleteImages("testcopyimg")
685
-
686 686
 	logDone("build - copy single file to workdir")
687 687
 }
688 688