Merge pull request #8565 from LK4D4/remove_fixtures_copy_tests

Remove fixtures copy tests
This commit is contained in:
Jessie Frazelle 2014-10-17 13:10:30 -07:00
commit b357f76e5d
23 changed files with 180 additions and 186 deletions

View File

@ -1,10 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir /exists
RUN touch /exists/exists_file
RUN chown -R dockerio.dockerio /exists
COPY test_dir/ /exists/
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]

View File

@ -1,8 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN touch /exists
RUN chown dockerio.dockerio exists
COPY test_dir /
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]

View File

@ -1,2 +0,0 @@
FROM busybox
COPY https://index.docker.io/robots.txt /

View File

@ -1,2 +0,0 @@
FROM scratch
COPY . /

View File

@ -1,17 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir /exists
RUN touch /exists/exists_file
RUN chown -R dockerio.dockerio /exists
COPY test_file1 test_file2 /exists/
ADD test_file3 test_file4 https://docker.com/robots.txt /exists/
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/test_file1 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/test_file2 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/test_file3 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/test_file4 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/robots.txt | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]

View File

@ -1,7 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir /exists
RUN chown -R dockerio.dockerio /exists
COPY test_file1 /exists/
ADD test_file2 test_file3 /exists/test_file1

View File

@ -1,10 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir /exists
RUN touch /exists/exists_file
RUN chown -R dockerio.dockerio /exists
COPY test_file /exists/
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]

View File

@ -1,9 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN touch /exists
RUN chown dockerio.dockerio /exists
COPY test_file /test_dir/
RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]

View File

@ -1,9 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN touch /exists
RUN chown dockerio.dockerio /exists
COPY test_file /
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /test_file | awk '{print $1}') = '-rw-r--r--' ]
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]

View File

@ -1,2 +0,0 @@
FROM busybox
COPY test_file .

View File

@ -1,11 +0,0 @@
FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN touch /exists
RUN chown dockerio.dockerio exists
COPY test_dir /test_dir
RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ]
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '-rw-r--r--' ]
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]

View File

@ -304,13 +304,40 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
} }
func TestBuildCopyAddMultipleFiles(t *testing.T) { func TestBuildCopyAddMultipleFiles(t *testing.T) {
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") name := "testcopymultiplefilestofile"
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testaddimg", "MultipleFiles"); err != nil { defer deleteImages(name)
t.Fatalf("build failed to complete: %s, %v", out, err) ctx, err := fakeContext(`FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir /exists
RUN touch /exists/exists_file
RUN chown -R dockerio.dockerio /exists
COPY test_file1 test_file2 /exists/
ADD test_file3 test_file4 https://docker.com/robots.txt /exists/
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/test_file1 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/test_file2 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/test_file3 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/test_file4 | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/robots.txt | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
`,
map[string]string{
"test_file1": "test1",
"test_file2": "test2",
"test_file3": "test3",
"test_file4": "test4",
})
defer ctx.Close()
if err != nil {
t.Fatal(err)
} }
deleteImages("testaddimg") if _, err := buildImageFromContext(name, ctx, true); err != nil {
t.Fatal(err)
}
logDone("build - mulitple file copy/add tests") logDone("build - mulitple file copy/add tests")
} }
@ -609,151 +636,205 @@ ADD . /`,
} }
func TestBuildCopySingleFileToRoot(t *testing.T) { func TestBuildCopySingleFileToRoot(t *testing.T) {
testDirName := "SingleFileToRoot" name := "testcopysinglefiletoroot"
sourceDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy", testDirName) defer deleteImages(name)
buildDirectory, err := ioutil.TempDir("", "test-build-add") ctx, err := fakeContext(`FROM busybox
defer os.RemoveAll(buildDirectory) RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
err = copyWithCP(sourceDirectory, buildDirectory) RUN touch /exists
if err != nil { RUN chown dockerio.dockerio /exists
t.Fatalf("failed to copy files to temporary directory: %s", err) COPY test_file /
} RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /test_file | awk '{print $1}') = '-rw-r--r--' ]
buildDirectory = filepath.Join(buildDirectory, testDirName) RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
f, err := os.OpenFile(filepath.Join(buildDirectory, "test_file"), os.O_CREATE, 0644) map[string]string{
"test_file": "test1",
})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
f.Close() if _, err := buildImageFromContext(name, ctx, true); err != nil {
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "."); err != nil { t.Fatal(err)
t.Fatalf("build failed to complete: %s, %v", out, err)
} }
deleteImages("testcopyimg")
logDone("build - copy single file to root") logDone("build - copy single file to root")
} }
// Issue #3960: "ADD src ." hangs - adapted for COPY // Issue #3960: "ADD src ." hangs - adapted for COPY
func TestBuildCopySingleFileToWorkdir(t *testing.T) { func TestBuildCopySingleFileToWorkdir(t *testing.T) {
testDirName := "SingleFileToWorkdir" name := "testcopysinglefiletoworkdir"
sourceDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy", testDirName) defer deleteImages(name)
buildDirectory, err := ioutil.TempDir("", "test-build-add") ctx, err := fakeContext(`FROM busybox
defer os.RemoveAll(buildDirectory) COPY test_file .`,
map[string]string{
err = copyWithCP(sourceDirectory, buildDirectory) "test_file": "test1",
if err != nil { })
t.Fatalf("failed to copy files to temporary directory: %s", err)
}
buildDirectory = filepath.Join(buildDirectory, testDirName)
f, err := os.OpenFile(filepath.Join(buildDirectory, "test_file"), os.O_CREATE, 0644)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
f.Close() done := make(chan struct{})
if out, _, err := dockerCmdInDirWithTimeout(5*time.Second, buildDirectory, "build", "-t", "testcopyimg", "."); err != nil { go func() {
t.Fatalf("build failed to complete: %s, %v", out, err) if _, err := buildImageFromContext(name, ctx, true); err != nil {
t.Fatal(err)
}
close(done)
}()
select {
case <-time.After(5 * time.Second):
t.Fatal("Build with adding to workdir timed out")
case <-done:
} }
deleteImages("testcopyimg")
logDone("build - copy single file to workdir") logDone("build - copy single file to workdir")
} }
func TestBuildCopySingleFileToExistDir(t *testing.T) { func TestBuildCopySingleFileToExistDir(t *testing.T) {
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") name := "testcopysinglefiletoexistdir"
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "SingleFileToExistDir"); err != nil { defer deleteImages(name)
t.Fatalf("build failed to complete: %s, %v", out, err) ctx, err := fakeContext(`FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir /exists
RUN touch /exists/exists_file
RUN chown -R dockerio.dockerio /exists
COPY test_file /exists/
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
map[string]string{
"test_file": "test1",
})
if err != nil {
t.Fatal(err)
}
if _, err := buildImageFromContext(name, ctx, true); err != nil {
t.Fatal(err)
} }
deleteImages("testcopyimg")
logDone("build - copy single file to existing dir") logDone("build - copy single file to existing dir")
} }
func TestBuildCopySingleFileToNonExistDir(t *testing.T) { func TestBuildCopySingleFileToNonExistDir(t *testing.T) {
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") name := "testcopysinglefiletononexistdir"
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "SingleFileToNonExistDir"); err != nil { defer deleteImages(name)
t.Fatalf("build failed to complete: %s, %v", out, err) ctx, err := fakeContext(`FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN touch /exists
RUN chown dockerio.dockerio /exists
COPY test_file /test_dir/
RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
map[string]string{
"test_file": "test1",
})
if err != nil {
t.Fatal(err)
}
if _, err := buildImageFromContext(name, ctx, true); err != nil {
t.Fatal(err)
} }
deleteImages("testcopyimg")
logDone("build - copy single file to non-existing dir") logDone("build - copy single file to non-existing dir")
} }
func TestBuildCopyDirContentToRoot(t *testing.T) { func TestBuildCopyDirContentToRoot(t *testing.T) {
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") name := "testcopydircontenttoroot"
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "DirContentToRoot"); err != nil { defer deleteImages(name)
t.Fatalf("build failed to complete: %s, %v", out, err) ctx, err := fakeContext(`FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN touch /exists
RUN chown dockerio.dockerio exists
COPY test_dir /
RUN [ $(ls -l /test_file | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
map[string]string{
"test_dir/test_file": "test1",
})
if err != nil {
t.Fatal(err)
}
if _, err := buildImageFromContext(name, ctx, true); err != nil {
t.Fatal(err)
} }
deleteImages("testcopyimg")
logDone("build - copy directory contents to root") logDone("build - copy directory contents to root")
} }
func TestBuildCopyDirContentToExistDir(t *testing.T) { func TestBuildCopyDirContentToExistDir(t *testing.T) {
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") name := "testcopydircontenttoexistdir"
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "DirContentToExistDir"); err != nil { defer deleteImages(name)
t.Fatalf("build failed to complete: %s, %v", out, err) ctx, err := fakeContext(`FROM busybox
RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
RUN mkdir /exists
RUN touch /exists/exists_file
RUN chown -R dockerio.dockerio /exists
COPY test_dir/ /exists/
RUN [ $(ls -l / | grep exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio' ]
RUN [ $(ls -l /exists/test_file | awk '{print $3":"$4}') = 'root:root' ]`,
map[string]string{
"test_dir/test_file": "test1",
})
if err != nil {
t.Fatal(err)
}
if _, err := buildImageFromContext(name, ctx, true); err != nil {
t.Fatal(err)
} }
deleteImages("testcopyimg")
logDone("build - copy directory contents to existing dir") logDone("build - copy directory contents to existing dir")
} }
func TestBuildCopyWholeDirToRoot(t *testing.T) { func TestBuildCopyWholeDirToRoot(t *testing.T) {
testDirName := "WholeDirToRoot" name := "testcopywholedirtoroot"
sourceDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy", testDirName) defer deleteImages(name)
buildDirectory, err := ioutil.TempDir("", "test-build-add") ctx, err := fakeContext(`FROM busybox
defer os.RemoveAll(buildDirectory) RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd
RUN echo 'dockerio:x:1001:' >> /etc/group
err = copyWithCP(sourceDirectory, buildDirectory) RUN touch /exists
if err != nil { RUN chown dockerio.dockerio exists
t.Fatalf("failed to copy files to temporary directory: %s", err) COPY test_dir /test_dir
} RUN [ $(ls -l / | grep test_dir | awk '{print $3":"$4}') = 'root:root' ]
RUN [ $(ls -l / | grep test_dir | awk '{print $1}') = 'drwxr-xr-x' ]
buildDirectory = filepath.Join(buildDirectory, testDirName) RUN [ $(ls -l /test_dir/test_file | awk '{print $3":"$4}') = 'root:root' ]
testDir := filepath.Join(buildDirectory, "test_dir") RUN [ $(ls -l /test_dir/test_file | awk '{print $1}') = '-rw-r--r--' ]
if err := os.MkdirAll(testDir, 0755); err != nil { RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`,
t.Fatal(err) map[string]string{
} "test_dir/test_file": "test1",
f, err := os.OpenFile(filepath.Join(testDir, "test_file"), os.O_CREATE, 0644) })
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
f.Close() if _, err := buildImageFromContext(name, ctx, true); err != nil {
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "."); err != nil { t.Fatal(err)
t.Fatalf("build failed to complete: %s, %v", out, err)
} }
deleteImages("testcopyimg")
logDone("build - copy whole directory to root") logDone("build - copy whole directory to root")
} }
func TestBuildCopyEtcToRoot(t *testing.T) { func TestBuildCopyEtcToRoot(t *testing.T) {
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") name := "testcopyetctoroot"
if out, _, err := dockerCmdInDir(t, buildDirectory, "build", "-t", "testcopyimg", "EtcToRoot"); err != nil { defer deleteImages(name)
t.Fatalf("build failed to complete: %s, %v", out, err) ctx, err := fakeContext(`FROM scratch
COPY . /`,
map[string]string{
"etc/test_file": "test1",
})
if err != nil {
t.Fatal(err)
}
if _, err := buildImageFromContext(name, ctx, true); err != nil {
t.Fatal(err)
} }
deleteImages("testcopyimg")
logDone("build - copy etc directory to root") logDone("build - copy etc directory to root")
} }
func TestBuildCopyDisallowRemote(t *testing.T) { func TestBuildCopyDisallowRemote(t *testing.T) {
buildDirectory := filepath.Join(workingDirectory, "build_tests", "TestCopy") name := "testcopydisallowremote"
buildCmd := exec.Command(dockerBinary, "build", "-t", "testcopyimg", "DisallowRemote") defer deleteImages(name)
buildCmd.Dir = buildDirectory _, out, err := buildImageWithOut(name, `FROM scratch
if out, _, err := runCommandWithOutput(buildCmd); err == nil { COPY https://index.docker.io/robots.txt /`,
t.Fatalf("building the image should've failed; output: %s", out) true)
if err == nil || !strings.Contains(out, "Source can't be a URL for COPY") {
t.Fatal("Error should be about disallowed remote source, got err: %s, out: %q", err, out)
} }
deleteImages("testcopyimg")
logDone("build - copy - disallow copy from remote") logDone("build - copy - disallow copy from remote")
} }