Merge pull request #7122 from LK4D4/move_some_run_tests_to_cli

Move some run tests to cli
This commit is contained in:
Michael Crosby
2014-07-21 11:25:36 -07:00
2 changed files with 53 additions and 94 deletions
+53
View File
@@ -1361,3 +1361,56 @@ func TestState(t *testing.T) {
}
logDone("run - test container state.")
}
// Test for #1737
func TestCopyVolumeUidGid(t *testing.T) {
name := "testrunvolumesuidgid"
defer deleteImages(name)
defer deleteAllContainers()
_, err := buildImage(name,
`FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir -p /hello && touch /hello/test && chown dockerio.dockerio /hello`,
true)
if err != nil {
t.Fatal(err)
}
// Test that the uid and gid is copied from the image to the volume
cmd := exec.Command(dockerBinary, "run", "--rm", "-v", "/hello", name, "sh", "-c", "ls -l / | grep hello | awk '{print $3\":\"$4}'")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
out = strings.TrimSpace(out)
if out != "dockerio:dockerio" {
t.Fatalf("Wrong /hello ownership: %s, expected dockerio:dockerio", out)
}
logDone("run - copy uid/gid for volume")
}
// Test for #1582
func TestCopyVolumeContent(t *testing.T) {
name := "testruncopyvolumecontent"
defer deleteImages(name)
defer deleteAllContainers()
_, err := buildImage(name,
`FROM busybox
RUN mkdir -p /hello/local && echo hello > /hello/local/world`,
true)
if err != nil {
t.Fatal(err)
}
// Test that the content is copied from the image to the volume
cmd := exec.Command(dockerBinary, "run", "--rm", "-v", "/hello", name, "sh", "-c", "find", "/hello")
out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
if !(strings.Contains(out, "/hello/local/world") && strings.Contains(out, "/hello/local")) {
t.Fatal("Container failed to transfer content to volume")
}
}
-94
View File
@@ -370,100 +370,6 @@ func tempDir(t *testing.T) string {
return tmpDir
}
// Test for #1737
func TestCopyVolumeUidGid(t *testing.T) {
eng := NewTestEngine(t)
r := mkDaemonFromEngine(eng, t)
defer r.Nuke()
// Add directory not owned by root
container1, _, _ := mkContainer(r, []string{"_", "/bin/sh", "-c", "mkdir -p /hello && touch /hello/test && chown daemon.daemon /hello"}, t)
defer r.Destroy(container1)
if container1.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
if err := container1.Run(); err != nil {
t.Fatal(err)
}
if container1.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
img, err := r.Commit(container1, "", "", "unit test commited image", "", true, nil)
if err != nil {
t.Error(err)
}
// Test that the uid and gid is copied from the image to the volume
tmpDir1 := tempDir(t)
defer os.RemoveAll(tmpDir1)
stdout1, _ := runContainer(eng, r, []string{"-v", "/hello", img.ID, "stat", "-c", "%U %G", "/hello"}, t)
if !strings.Contains(stdout1, "daemon daemon") {
t.Fatal("Container failed to transfer uid and gid to volume")
}
container2, _, _ := mkContainer(r, []string{"_", "/bin/sh", "-c", "mkdir -p /hello && chown daemon.daemon /hello"}, t)
defer r.Destroy(container1)
if container2.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
if err := container2.Run(); err != nil {
t.Fatal(err)
}
if container2.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
img2, err := r.Commit(container2, "", "", "unit test commited image", "", true, nil)
if err != nil {
t.Error(err)
}
// Test that the uid and gid is copied from the image to the volume
tmpDir2 := tempDir(t)
defer os.RemoveAll(tmpDir2)
stdout2, _ := runContainer(eng, r, []string{"-v", "/hello", img2.ID, "stat", "-c", "%U %G", "/hello"}, t)
if !strings.Contains(stdout2, "daemon daemon") {
t.Fatal("Container failed to transfer uid and gid to volume")
}
}
// Test for #1582
func TestCopyVolumeContent(t *testing.T) {
eng := NewTestEngine(t)
r := mkDaemonFromEngine(eng, t)
defer r.Nuke()
// Put some content in a directory of a container and commit it
container1, _, _ := mkContainer(r, []string{"_", "/bin/sh", "-c", "mkdir -p /hello/local && echo hello > /hello/local/world"}, t)
defer r.Destroy(container1)
if container1.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
if err := container1.Run(); err != nil {
t.Fatal(err)
}
if container1.State.IsRunning() {
t.Errorf("Container shouldn't be running")
}
img, err := r.Commit(container1, "", "", "unit test commited image", "", true, nil)
if err != nil {
t.Error(err)
}
// Test that the content is copied from the image to the volume
tmpDir1 := tempDir(t)
defer os.RemoveAll(tmpDir1)
stdout1, _ := runContainer(eng, r, []string{"-v", "/hello", img.ID, "find", "/hello"}, t)
if !(strings.Contains(stdout1, "/hello/local/world") && strings.Contains(stdout1, "/hello/local")) {
t.Fatal("Container failed to transfer content to volume")
}
}
func TestBindMounts(t *testing.T) {
eng := NewTestEngine(t)
r := mkDaemonFromEngine(eng, t)