Browse code

Move TestCopyVolumeUidGid to integration-cli

Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)

LK4D4 authored on 2014/07/17 04:40:04
Showing 2 changed files
... ...
@@ -1361,3 +1361,32 @@ func TestState(t *testing.T) {
1361 1361
 	}
1362 1362
 	logDone("run - test container state.")
1363 1363
 }
1364
+
1365
+// Test for #1737
1366
+func TestCopyVolumeUidGid(t *testing.T) {
1367
+	name := "testrunvolumesuidgid"
1368
+	defer deleteImages(name)
1369
+	defer deleteAllContainers()
1370
+	_, err := buildImage(name,
1371
+		`FROM busybox
1372
+		RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
1373
+		RUN echo 'dockerio:x:1001:' >> /etc/group
1374
+		RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`,
1375
+		true)
1376
+	if err != nil {
1377
+		t.Fatal(err)
1378
+	}
1379
+
1380
+	// Test that the uid and gid is copied from the image to the volume
1381
+	cmd := exec.Command(dockerBinary, "run", "--rm", "-v", "/hello", name, "sh", "-c", "ls -l / | grep hello | awk '{print $3\":\"$4}'")
1382
+	out, _, err := runCommandWithOutput(cmd)
1383
+	if err != nil {
1384
+		t.Fatal(err, out)
1385
+	}
1386
+	out = strings.TrimSpace(out)
1387
+	if out != "dockerio:dockerio" {
1388
+		t.Fatalf("Wrong /hello ownership: %s, expected dockerio:dockerio", out)
1389
+	}
1390
+
1391
+	logDone("run - copy uid/gid for volume")
1392
+}
... ...
@@ -370,66 +370,6 @@ func tempDir(t *testing.T) string {
370 370
 	return tmpDir
371 371
 }
372 372
 
373
-// Test for #1737
374
-func TestCopyVolumeUidGid(t *testing.T) {
375
-	eng := NewTestEngine(t)
376
-	r := mkDaemonFromEngine(eng, t)
377
-	defer r.Nuke()
378
-
379
-	// Add directory not owned by root
380
-	container1, _, _ := mkContainer(r, []string{"_", "/bin/sh", "-c", "mkdir -p /hello && touch /hello/test && chown daemon.daemon /hello"}, t)
381
-	defer r.Destroy(container1)
382
-
383
-	if container1.State.IsRunning() {
384
-		t.Errorf("Container shouldn't be running")
385
-	}
386
-	if err := container1.Run(); err != nil {
387
-		t.Fatal(err)
388
-	}
389
-	if container1.State.IsRunning() {
390
-		t.Errorf("Container shouldn't be running")
391
-	}
392
-
393
-	img, err := r.Commit(container1, "", "", "unit test commited image", "", true, nil)
394
-	if err != nil {
395
-		t.Error(err)
396
-	}
397
-
398
-	// Test that the uid and gid is copied from the image to the volume
399
-	tmpDir1 := tempDir(t)
400
-	defer os.RemoveAll(tmpDir1)
401
-	stdout1, _ := runContainer(eng, r, []string{"-v", "/hello", img.ID, "stat", "-c", "%U %G", "/hello"}, t)
402
-	if !strings.Contains(stdout1, "daemon daemon") {
403
-		t.Fatal("Container failed to transfer uid and gid to volume")
404
-	}
405
-
406
-	container2, _, _ := mkContainer(r, []string{"_", "/bin/sh", "-c", "mkdir -p /hello && chown daemon.daemon /hello"}, t)
407
-	defer r.Destroy(container1)
408
-
409
-	if container2.State.IsRunning() {
410
-		t.Errorf("Container shouldn't be running")
411
-	}
412
-	if err := container2.Run(); err != nil {
413
-		t.Fatal(err)
414
-	}
415
-	if container2.State.IsRunning() {
416
-		t.Errorf("Container shouldn't be running")
417
-	}
418
-
419
-	img2, err := r.Commit(container2, "", "", "unit test commited image", "", true, nil)
420
-	if err != nil {
421
-		t.Error(err)
422
-	}
423
-
424
-	// Test that the uid and gid is copied from the image to the volume
425
-	tmpDir2 := tempDir(t)
426
-	defer os.RemoveAll(tmpDir2)
427
-	stdout2, _ := runContainer(eng, r, []string{"-v", "/hello", img2.ID, "stat", "-c", "%U %G", "/hello"}, t)
428
-	if !strings.Contains(stdout2, "daemon daemon") {
429
-		t.Fatal("Container failed to transfer uid and gid to volume")
430
-	}
431
-}
432
-
433 373
 // Test for #1582
434 374
 func TestCopyVolumeContent(t *testing.T) {
435 375
 	eng := NewTestEngine(t)