summaryrefslogtreecommitdiff
path: root/integration-cli/docker_cli_cp_test.go
diff options
context:
space:
mode:
authorAlexander Morozov <lk4d4@docker.com>2015-04-18 09:46:47 -0700
committerAlexander Morozov <lk4d4@docker.com>2015-04-21 10:28:52 -0700
commitdc944ea7e48d11a2906e751d3e61daf08faee054 (patch)
treebc2c7f5ee0bd7cec72c7af64358554a130a0ddd6 /integration-cli/docker_cli_cp_test.go
parent6dcdf832a3dddc8de17b7f8b1fb1ddb8b20f9077 (diff)
downloaddocker-dc944ea7e48d11a2906e751d3e61daf08faee054.tar.gz
Use suite for integration-cli
It prints test name and duration for each test. Also performs deleteAllContainers after each test. Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Diffstat (limited to 'integration-cli/docker_cli_cp_test.go')
-rw-r--r--integration-cli/docker_cli_cp_test.go290
1 files changed, 140 insertions, 150 deletions
diff --git a/integration-cli/docker_cli_cp_test.go b/integration-cli/docker_cli_cp_test.go
index b577e82982..022b3cc9ea 100644
--- a/integration-cli/docker_cli_cp_test.go
+++ b/integration-cli/docker_cli_cp_test.go
@@ -9,7 +9,8 @@ import (
"path"
"path/filepath"
"strings"
- "testing"
+
+ "github.com/go-check/check"
)
const (
@@ -24,27 +25,27 @@ const (
// Test for #5656
// Check that garbage paths don't escape the container's rootfs
-func TestCpGarbagePath(t *testing.T) {
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
+func (s *DockerSuite) TestCpGarbagePath(c *check.C) {
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
hostFile, err := os.Create(cpFullPath)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer hostFile.Close()
defer os.RemoveAll(cpTestPathParent)
@@ -53,7 +54,7 @@ func TestCpGarbagePath(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
tmpname := filepath.Join(tmpdir, cpTestName)
@@ -61,49 +62,48 @@ func TestCpGarbagePath(t *testing.T) {
path := path.Join("../../../../../../../../../../../../", cpFullPath)
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
test, err := ioutil.ReadAll(file)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if string(test) == cpHostContents {
- t.Errorf("output matched host file -- garbage path can escape container rootfs")
+ c.Errorf("output matched host file -- garbage path can escape container rootfs")
}
if string(test) != cpContainerContents {
- t.Errorf("output doesn't match the input for garbage path")
+ c.Errorf("output doesn't match the input for garbage path")
}
- logDone("cp - garbage paths relative to container's rootfs")
}
// Check that relative paths are relative to the container's rootfs
-func TestCpRelativePath(t *testing.T) {
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
+func (s *DockerSuite) TestCpRelativePath(c *check.C) {
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
hostFile, err := os.Create(cpFullPath)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer hostFile.Close()
defer os.RemoveAll(cpTestPathParent)
@@ -113,7 +113,7 @@ func TestCpRelativePath(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
tmpname := filepath.Join(tmpdir, cpTestName)
@@ -125,52 +125,51 @@ func TestCpRelativePath(t *testing.T) {
// get this unix-path manipulation on windows with filepath.
relPath = cpFullPath[1:]
} else {
- t.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
+ c.Fatalf("path %s was assumed to be an absolute path", cpFullPath)
}
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":"+relPath, tmpdir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":"+relPath, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
test, err := ioutil.ReadAll(file)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if string(test) == cpHostContents {
- t.Errorf("output matched host file -- relative path can escape container rootfs")
+ c.Errorf("output matched host file -- relative path can escape container rootfs")
}
if string(test) != cpContainerContents {
- t.Errorf("output doesn't match the input for relative path")
+ c.Errorf("output doesn't match the input for relative path")
}
- logDone("cp - relative paths relative to container's rootfs")
}
// Check that absolute paths are relative to the container's rootfs
-func TestCpAbsolutePath(t *testing.T) {
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
+func (s *DockerSuite) TestCpAbsolutePath(c *check.C) {
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath)
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
hostFile, err := os.Create(cpFullPath)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer hostFile.Close()
defer os.RemoveAll(cpTestPathParent)
@@ -180,7 +179,7 @@ func TestCpAbsolutePath(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
tmpname := filepath.Join(tmpdir, cpTestName)
@@ -188,50 +187,49 @@ func TestCpAbsolutePath(t *testing.T) {
path := cpFullPath
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
test, err := ioutil.ReadAll(file)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if string(test) == cpHostContents {
- t.Errorf("output matched host file -- absolute path can escape container rootfs")
+ c.Errorf("output matched host file -- absolute path can escape container rootfs")
}
if string(test) != cpContainerContents {
- t.Errorf("output doesn't match the input for absolute path")
+ c.Errorf("output doesn't match the input for absolute path")
}
- logDone("cp - absolute paths relative to container's rootfs")
}
// Test for #5619
// Check that absolute symlinks are still relative to the container's rootfs
-func TestCpAbsoluteSymlink(t *testing.T) {
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
+func (s *DockerSuite) TestCpAbsoluteSymlink(c *check.C) {
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpFullPath+" container_path")
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
hostFile, err := os.Create(cpFullPath)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer hostFile.Close()
defer os.RemoveAll(cpTestPathParent)
@@ -241,7 +239,7 @@ func TestCpAbsoluteSymlink(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
tmpname := filepath.Join(tmpdir, cpTestName)
@@ -249,50 +247,49 @@ func TestCpAbsoluteSymlink(t *testing.T) {
path := path.Join("/", "container_path")
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
test, err := ioutil.ReadAll(file)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if string(test) == cpHostContents {
- t.Errorf("output matched host file -- absolute symlink can escape container rootfs")
+ c.Errorf("output matched host file -- absolute symlink can escape container rootfs")
}
if string(test) != cpContainerContents {
- t.Errorf("output doesn't match the input for absolute symlink")
+ c.Errorf("output doesn't match the input for absolute symlink")
}
- logDone("cp - absolute symlink relative to container's rootfs")
}
// Test for #5619
// Check that symlinks which are part of the resource path are still relative to the container's rootfs
-func TestCpSymlinkComponent(t *testing.T) {
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
+func (s *DockerSuite) TestCpSymlinkComponent(c *check.C) {
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "mkdir -p '"+cpTestPath+"' && echo -n '"+cpContainerContents+"' > "+cpFullPath+" && ln -s "+cpTestPath+" container_path")
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
if err := os.MkdirAll(cpTestPath, os.ModeDir); err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
hostFile, err := os.Create(cpFullPath)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer hostFile.Close()
defer os.RemoveAll(cpTestPathParent)
@@ -302,7 +299,7 @@ func TestCpSymlinkComponent(t *testing.T) {
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
tmpname := filepath.Join(tmpdir, cpTestName)
@@ -310,268 +307,263 @@ func TestCpSymlinkComponent(t *testing.T) {
path := path.Join("/", "container_path", cpTestName)
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":"+path, tmpdir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":"+path, tmpdir)
file, _ := os.Open(tmpname)
defer file.Close()
test, err := ioutil.ReadAll(file)
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if string(test) == cpHostContents {
- t.Errorf("output matched host file -- symlink path component can escape container rootfs")
+ c.Errorf("output matched host file -- symlink path component can escape container rootfs")
}
if string(test) != cpContainerContents {
- t.Errorf("output doesn't match the input for symlink path component")
+ c.Errorf("output doesn't match the input for symlink path component")
}
- logDone("cp - symlink path components relative to container's rootfs")
}
// Check that cp with unprivileged user doesn't return any error
-func TestCpUnprivilegedUser(t *testing.T) {
- testRequires(t, UnixCli) // uses chmod/su: not available on windows
+func (s *DockerSuite) TestCpUnprivilegedUser(c *check.C) {
+ testRequires(c, UnixCli) // uses chmod/su: not available on windows
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch "+cpTestName)
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer os.RemoveAll(tmpdir)
if err = os.Chmod(tmpdir, 0777); err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
path := cpTestName
_, _, err = runCommandWithOutput(exec.Command("su", "unprivilegeduser", "-c", dockerBinary+" cp "+cleanedContainerID+":"+path+" "+tmpdir))
if err != nil {
- t.Fatalf("couldn't copy with unprivileged user: %s:%s %s", cleanedContainerID, path, err)
+ c.Fatalf("couldn't copy with unprivileged user: %s:%s %s", cleanedContainerID, path, err)
}
- logDone("cp - unprivileged user")
}
-func TestCpSpecialFiles(t *testing.T) {
- testRequires(t, SameHostDaemon)
+func (s *DockerSuite) TestCpSpecialFiles(c *check.C) {
+ testRequires(c, SameHostDaemon)
outDir, err := ioutil.TempDir("", "cp-test-special-files")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer os.RemoveAll(outDir)
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
// Copy actual /etc/resolv.conf
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
expected, err := ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/resolv.conf")
actual, err := ioutil.ReadFile(outDir + "/resolv.conf")
if !bytes.Equal(actual, expected) {
- t.Fatalf("Expected copied file to be duplicate of the container resolvconf")
+ c.Fatalf("Expected copied file to be duplicate of the container resolvconf")
}
// Copy actual /etc/hosts
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/etc/hosts", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hosts", outDir)
expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hosts")
actual, err = ioutil.ReadFile(outDir + "/hosts")
if !bytes.Equal(actual, expected) {
- t.Fatalf("Expected copied file to be duplicate of the container hosts")
+ c.Fatalf("Expected copied file to be duplicate of the container hosts")
}
// Copy actual /etc/resolv.conf
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/etc/hostname", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/etc/hostname", outDir)
expected, err = ioutil.ReadFile("/var/lib/docker/containers/" + cleanedContainerID + "/hostname")
actual, err = ioutil.ReadFile(outDir + "/hostname")
if !bytes.Equal(actual, expected) {
- t.Fatalf("Expected copied file to be duplicate of the container resolvconf")
+ c.Fatalf("Expected copied file to be duplicate of the container resolvconf")
}
- logDone("cp - special files (resolv.conf, hosts, hostname)")
}
-func TestCpVolumePath(t *testing.T) {
- testRequires(t, SameHostDaemon)
+func (s *DockerSuite) TestCpVolumePath(c *check.C) {
+ testRequires(c, SameHostDaemon)
tmpDir, err := ioutil.TempDir("", "cp-test-volumepath")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer os.RemoveAll(tmpDir)
outDir, err := ioutil.TempDir("", "cp-test-volumepath-out")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer os.RemoveAll(outDir)
_, err = os.Create(tmpDir + "/test")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
- out, exitCode := dockerCmd(t, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar")
+ out, exitCode := dockerCmd(c, "run", "-d", "-v", "/foo", "-v", tmpDir+"/test:/test", "-v", tmpDir+":/baz", "busybox", "/bin/sh", "-c", "touch /foo/bar")
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
- defer dockerCmd(t, "rm", "-fv", cleanedContainerID)
+ defer dockerCmd(c, "rm", "-fv", cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
// Copy actual volume path
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/foo", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo", outDir)
stat, err := os.Stat(outDir + "/foo")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if !stat.IsDir() {
- t.Fatal("expected copied content to be dir")
+ c.Fatal("expected copied content to be dir")
}
stat, err = os.Stat(outDir + "/foo/bar")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if stat.IsDir() {
- t.Fatal("Expected file `bar` to be a file")
+ c.Fatal("Expected file `bar` to be a file")
}
// Copy file nested in volume
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/foo/bar", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/foo/bar", outDir)
stat, err = os.Stat(outDir + "/bar")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if stat.IsDir() {
- t.Fatal("Expected file `bar` to be a file")
+ c.Fatal("Expected file `bar` to be a file")
}
// Copy Bind-mounted dir
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/baz", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz", outDir)
stat, err = os.Stat(outDir + "/baz")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if !stat.IsDir() {
- t.Fatal("Expected `baz` to be a dir")
+ c.Fatal("Expected `baz` to be a dir")
}
// Copy file nested in bind-mounted dir
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/baz/test", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/baz/test", outDir)
fb, err := ioutil.ReadFile(outDir + "/baz/test")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
fb2, err := ioutil.ReadFile(tmpDir + "/test")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if !bytes.Equal(fb, fb2) {
- t.Fatalf("Expected copied file to be duplicate of bind-mounted file")
+ c.Fatalf("Expected copied file to be duplicate of bind-mounted file")
}
// Copy bind-mounted file
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/test", outDir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", outDir)
fb, err = ioutil.ReadFile(outDir + "/test")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
fb2, err = ioutil.ReadFile(tmpDir + "/test")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
if !bytes.Equal(fb, fb2) {
- t.Fatalf("Expected copied file to be duplicate of bind-mounted file")
+ c.Fatalf("Expected copied file to be duplicate of bind-mounted file")
}
- logDone("cp - volume path")
}
-func TestCpToDot(t *testing.T) {
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
+func (s *DockerSuite) TestCpToDot(c *check.C) {
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer os.RemoveAll(tmpdir)
cwd, err := os.Getwd()
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer os.Chdir(cwd)
if err := os.Chdir(tmpdir); err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/test", ".")
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/test", ".")
content, err := ioutil.ReadFile("./test")
if string(content) != "lololol\n" {
- t.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
+ c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
}
- logDone("cp - to dot path")
}
-func TestCpToStdout(t *testing.T) {
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
+func (s *DockerSuite) TestCpToStdout(c *check.C) {
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /test")
if exitCode != 0 {
- t.Fatalf("failed to create a container:%s\n", out)
+ c.Fatalf("failed to create a container:%s\n", out)
}
cID := strings.TrimSpace(out)
defer deleteContainer(cID)
- out, _ = dockerCmd(t, "wait", cID)
+ out, _ = dockerCmd(c, "wait", cID)
if strings.TrimSpace(out) != "0" {
- t.Fatalf("failed to set up container:%s\n", out)
+ c.Fatalf("failed to set up container:%s\n", out)
}
out, _, err := runCommandPipelineWithOutput(
@@ -579,40 +571,38 @@ func TestCpToStdout(t *testing.T) {
exec.Command("tar", "-vtf", "-"))
if err != nil {
- t.Fatalf("Failed to run commands: %s", err)
+ c.Fatalf("Failed to run commands: %s", err)
}
if !strings.Contains(out, "test") || !strings.Contains(out, "-rw") {
- t.Fatalf("Missing file from tar TOC:\n%s", out)
+ c.Fatalf("Missing file from tar TOC:\n%s", out)
}
- logDone("cp - to stdout")
}
-func TestCpNameHasColon(t *testing.T) {
- testRequires(t, SameHostDaemon)
+func (s *DockerSuite) TestCpNameHasColon(c *check.C) {
+ testRequires(c, SameHostDaemon)
- out, exitCode := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
+ out, exitCode := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", "echo lololol > /te:s:t")
if exitCode != 0 {
- t.Fatal("failed to create a container", out)
+ c.Fatal("failed to create a container", out)
}
cleanedContainerID := strings.TrimSpace(out)
defer deleteContainer(cleanedContainerID)
- out, _ = dockerCmd(t, "wait", cleanedContainerID)
+ out, _ = dockerCmd(c, "wait", cleanedContainerID)
if strings.TrimSpace(out) != "0" {
- t.Fatal("failed to set up container", out)
+ c.Fatal("failed to set up container", out)
}
tmpdir, err := ioutil.TempDir("", "docker-integration")
if err != nil {
- t.Fatal(err)
+ c.Fatal(err)
}
defer os.RemoveAll(tmpdir)
- _, _ = dockerCmd(t, "cp", cleanedContainerID+":/te:s:t", tmpdir)
+ _, _ = dockerCmd(c, "cp", cleanedContainerID+":/te:s:t", tmpdir)
content, err := ioutil.ReadFile(tmpdir + "/te:s:t")
if string(content) != "lololol\n" {
- t.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
+ c.Fatalf("Wrong content in copied file %q, should be %q", content, "lololol\n")
}
- logDone("cp - copy filename has ':'")
}