summaryrefslogtreecommitdiff
path: root/integration-cli/docker_cli_cp_test.go
diff options
context:
space:
mode:
authorVincent Demeester <vincent@sbr.pm>2015-03-29 12:58:57 +0200
committerVincent Demeester <vincent@sbr.pm>2015-03-29 22:10:14 +0200
commit8bc330d8632ef0129b433b877a5e2fc88bb2eb39 (patch)
tree7cb68a390891a220f9bf8935c412080ed4c0c150 /integration-cli/docker_cli_cp_test.go
parent1f27ebc2c79becebe489f555ff02cef93a2b16be (diff)
downloaddocker-8bc330d8632ef0129b433b877a5e2fc88bb2eb39.tar.gz
Docker cp handles resolv.conf, hostname & hosts, fixes #9998
Add a integration test TestCpSpecialFiles Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Diffstat (limited to 'integration-cli/docker_cli_cp_test.go')
-rw-r--r--integration-cli/docker_cli_cp_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/integration-cli/docker_cli_cp_test.go b/integration-cli/docker_cli_cp_test.go
index db5f363882..c202892611 100644
--- a/integration-cli/docker_cli_cp_test.go
+++ b/integration-cli/docker_cli_cp_test.go
@@ -384,6 +384,70 @@ func TestCpUnprivilegedUser(t *testing.T) {
logDone("cp - unprivileged user")
}
+func TestCpSpecialFiles(t *testing.T) {
+ testRequires(t, SameHostDaemon)
+
+ outDir, err := ioutil.TempDir("", "cp-test-special-files")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(outDir)
+
+ out, exitCode, err := dockerCmd(t, "run", "-d", "busybox", "/bin/sh", "-c", "touch /foo")
+ if err != nil || exitCode != 0 {
+ t.Fatal("failed to create a container", out, err)
+ }
+
+ cleanedContainerID := stripTrailingCharacters(out)
+ defer deleteContainer(cleanedContainerID)
+
+ out, _, err = dockerCmd(t, "wait", cleanedContainerID)
+ if err != nil || stripTrailingCharacters(out) != "0" {
+ t.Fatal("failed to set up container", out, err)
+ }
+
+ // Copy actual /etc/resolv.conf
+ _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/etc/resolv.conf", outDir)
+ if err != nil {
+ t.Fatalf("couldn't copy from container: %s:%s %v", cleanedContainerID, "/etc/resolv.conf", err)
+ }
+
+ 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")
+ }
+
+ // Copy actual /etc/hosts
+ _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/etc/hosts", outDir)
+ if err != nil {
+ t.Fatalf("couldn't copy from container: %s:%s %v", cleanedContainerID, "/etc/hosts", err)
+ }
+
+ 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")
+ }
+
+ // Copy actual /etc/resolv.conf
+ _, _, err = dockerCmd(t, "cp", cleanedContainerID+":/etc/hostname", outDir)
+ if err != nil {
+ t.Fatalf("couldn't copy from container: %s:%s %v", cleanedContainerID, "/etc/hostname", err)
+ }
+
+ 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")
+ }
+
+ logDone("cp - special files (resolv.conf, hosts, hostname)")
+}
+
func TestCpVolumePath(t *testing.T) {
testRequires(t, SameHostDaemon)