Browse code

integ-cli: add test for links in volumes

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>

unclejack authored on 2014/11/28 05:39:43
Showing 1 changed files
... ...
@@ -1385,6 +1385,58 @@ func TestBuildAddBadLinks(t *testing.T) {
1385 1385
 	logDone("build - ADD must add files in container")
1386 1386
 }
1387 1387
 
1388
+func TestBuildAddBadLinksVolume(t *testing.T) {
1389
+	const (
1390
+		dockerfileTemplate = `
1391
+		FROM busybox
1392
+		RUN ln -s /../../../../../../../../%s /x
1393
+		VOLUME /x
1394
+		ADD foo.txt /x/`
1395
+		targetFile = "foo.txt"
1396
+	)
1397
+	var (
1398
+		name       = "test-link-absolute-volume"
1399
+		dockerfile = ""
1400
+	)
1401
+	defer deleteImages(name)
1402
+
1403
+	tempDir, err := ioutil.TempDir("", "test-link-absolute-volume-temp-")
1404
+	if err != nil {
1405
+		t.Fatalf("failed to create temporary directory: %s", tempDir)
1406
+	}
1407
+	defer os.RemoveAll(tempDir)
1408
+
1409
+	dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir)
1410
+	nonExistingFile := filepath.Join(tempDir, targetFile)
1411
+
1412
+	ctx, err := fakeContext(dockerfile, nil)
1413
+	if err != nil {
1414
+		t.Fatal(err)
1415
+	}
1416
+	defer ctx.Close()
1417
+	fooPath := filepath.Join(ctx.Dir, targetFile)
1418
+
1419
+	foo, err := os.Create(fooPath)
1420
+	if err != nil {
1421
+		t.Fatal(err)
1422
+	}
1423
+	defer foo.Close()
1424
+
1425
+	if _, err := foo.WriteString("test"); err != nil {
1426
+		t.Fatal(err)
1427
+	}
1428
+
1429
+	if _, err := buildImageFromContext(name, ctx, true); err != nil {
1430
+		t.Fatal(err)
1431
+	}
1432
+
1433
+	if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) {
1434
+		t.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile)
1435
+	}
1436
+
1437
+	logDone("build - ADD should add files in volume")
1438
+}
1439
+
1388 1440
 // Issue #5270 - ensure we throw a better error than "unexpected EOF"
1389 1441
 // when we can't access files in the context.
1390 1442
 func TestBuildWithInaccessibleFilesInContext(t *testing.T) {