瀏覽代碼

Add testcases for ADD caching, closes #880.

Graydon Hoare 11 年之前
父節點
當前提交
15a6854119
共有 1 個文件被更改,包括 93 次插入27 次删除
  1. 93 27
      integration/buildfile_test.go

+ 93 - 27
integration/buildfile_test.go

@@ -425,16 +425,10 @@ func TestBuildEntrypointRunCleanup(t *testing.T) {
 	}
 }
 
-func TestBuildImageWithCache(t *testing.T) {
+func checkCacheBehavior(t *testing.T, template testContextTemplate, expectHit bool) {
 	eng := NewTestEngine(t)
 	defer nuke(mkRuntimeFromEngine(eng, t))
 
-	template := testContextTemplate{`
-        from {IMAGE}
-        maintainer dockerio
-        `,
-		nil, nil}
-
 	img, err := buildImage(template, t, eng, true)
 	if err != nil {
 		t.Fatal(err)
@@ -443,43 +437,115 @@ func TestBuildImageWithCache(t *testing.T) {
 	imageId := img.ID
 
 	img = nil
-	img, err = buildImage(template, t, eng, true)
+	img, err = buildImage(template, t, eng, expectHit)
 	if err != nil {
 		t.Fatal(err)
 	}
 
-	if imageId != img.ID {
-		t.Logf("Image ids should match: %s != %s", imageId, img.ID)
+	hit := imageId == img.ID
+	if hit != expectHit {
+		t.Logf("Cache misbehavior, got hit=%t, expected hit=%t: (first: %s, second %s)",
+			hit, expectHit, imageId, img.ID)
 		t.Fail()
 	}
 }
 
-func TestBuildImageWithoutCache(t *testing.T) {
-	eng := NewTestEngine(t)
-	defer nuke(mkRuntimeFromEngine(eng, t))
+func TestBuildImageWithCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        `,
+		nil, nil}
+	checkCacheBehavior(t, template, true)
+}
 
+func TestBuildImageWithoutCache(t *testing.T) {
 	template := testContextTemplate{`
         from {IMAGE}
         maintainer dockerio
         `,
 		nil, nil}
+	checkCacheBehavior(t, template, false)
+}
 
-	img, err := buildImage(template, t, eng, true)
-	if err != nil {
-		t.Fatal(err)
-	}
-	imageId := img.ID
+func TestBuildADDLocalFileWithCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        run echo "first"
+        add foo /usr/lib/bla/bar
+        run echo "second"
+        `,
+		[][2]string{{"foo", "hello"}},
+		nil}
+	checkCacheBehavior(t, template, true)
+}
 
-	img = nil
-	img, err = buildImage(template, t, eng, false)
-	if err != nil {
-		t.Fatal(err)
-	}
+func TestBuildADDLocalFileWithoutCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        run echo "first"
+        add foo /usr/lib/bla/bar
+        run echo "second"
+        `,
+		[][2]string{{"foo", "hello"}},
+		nil}
+	checkCacheBehavior(t, template, false)
+}
 
-	if imageId == img.ID {
-		t.Logf("Image ids should not match: %s == %s", imageId, img.ID)
-		t.Fail()
-	}
+func TestBuildADDRemoteFileWithCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        run echo "first"
+        add http://{SERVERADDR}/baz /usr/lib/baz/quux
+        run echo "second"
+        `,
+		nil,
+		[][2]string{{"/baz", "world!"}}}
+	checkCacheBehavior(t, template, true)
+}
+
+func TestBuildADDRemoteFileWithoutCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        run echo "first"
+        add http://{SERVERADDR}/baz /usr/lib/baz/quux
+        run echo "second"
+        `,
+		nil,
+		[][2]string{{"/baz", "world!"}}}
+	checkCacheBehavior(t, template, false)
+}
+
+func TestBuildADDLocalAndRemoteFilesWithCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        run echo "first"
+        add foo /usr/lib/bla/bar
+        add http://{SERVERADDR}/baz /usr/lib/baz/quux
+        run echo "second"
+        `,
+		[][2]string{{"foo", "hello"}},
+		[][2]string{{"/baz", "world!"}}}
+	checkCacheBehavior(t, template, true)
+}
+
+func TestBuildADDLocalAndRemoteFilesWithoutCache(t *testing.T) {
+	template := testContextTemplate{`
+        from {IMAGE}
+        maintainer dockerio
+        run echo "first"
+        add foo /usr/lib/bla/bar
+        add http://{SERVERADDR}/baz /usr/lib/baz/quux
+        run echo "second"
+        `,
+		[][2]string{{"foo", "hello"}},
+		[][2]string{{"/baz", "world!"}}}
+	checkCacheBehavior(t, template, false)
 }
 
 func TestForbiddenContextPath(t *testing.T) {