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
... ...
@@ -1242,6 +1242,58 @@ func TestBuildAddBadLinks(t *testing.T) {
1242 1242
 	logDone("build - ADD must add files in container")
1243 1243
 }
1244 1244
 
1245
+func TestBuildAddBadLinksVolume(t *testing.T) {
1246
+	const (
1247
+		dockerfileTemplate = `
1248
+		FROM busybox
1249
+		RUN ln -s /../../../../../../../../%s /x
1250
+		VOLUME /x
1251
+		ADD foo.txt /x/`
1252
+		targetFile = "foo.txt"
1253
+	)
1254
+	var (
1255
+		name       = "test-link-absolute-volume"
1256
+		dockerfile = ""
1257
+	)
1258
+	defer deleteImages(name)
1259
+
1260
+	tempDir, err := ioutil.TempDir("", "test-link-absolute-volume-temp-")
1261
+	if err != nil {
1262
+		t.Fatalf("failed to create temporary directory: %s", tempDir)
1263
+	}
1264
+	defer os.RemoveAll(tempDir)
1265
+
1266
+	dockerfile = fmt.Sprintf(dockerfileTemplate, tempDir)
1267
+	nonExistingFile := filepath.Join(tempDir, targetFile)
1268
+
1269
+	ctx, err := fakeContext(dockerfile, nil)
1270
+	if err != nil {
1271
+		t.Fatal(err)
1272
+	}
1273
+	defer ctx.Close()
1274
+	fooPath := filepath.Join(ctx.Dir, targetFile)
1275
+
1276
+	foo, err := os.Create(fooPath)
1277
+	if err != nil {
1278
+		t.Fatal(err)
1279
+	}
1280
+	defer foo.Close()
1281
+
1282
+	if _, err := foo.WriteString("test"); err != nil {
1283
+		t.Fatal(err)
1284
+	}
1285
+
1286
+	if _, err := buildImageFromContext(name, ctx, true); err != nil {
1287
+		t.Fatal(err)
1288
+	}
1289
+
1290
+	if _, err := os.Stat(nonExistingFile); err == nil || err != nil && !os.IsNotExist(err) {
1291
+		t.Fatalf("%s shouldn't have been written and it shouldn't exist", nonExistingFile)
1292
+	}
1293
+
1294
+	logDone("build - ADD should add files in volume")
1295
+}
1296
+
1245 1297
 // Issue #5270 - ensure we throw a better error than "unexpected EOF"
1246 1298
 // when we can't access files in the context.
1247 1299
 func TestBuildWithInaccessibleFilesInContext(t *testing.T) {