aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorQi Wang <qiwan@redhat.com>2019-04-26 17:27:06 -0400
committerQi Wang <qiwan@redhat.com>2019-05-09 10:12:39 -0400
commit4479b8eec3558daedfd519d577bf63a17f4b2642 (patch)
treeafd9fda59818e1f52345c35c012ad2c32a450b09 /test
parent83700a74f82f849146a890ca28a8968107e79910 (diff)
downloadpodman-4479b8eec3558daedfd519d577bf63a17f4b2642.tar.gz
podman-4479b8eec3558daedfd519d577bf63a17f4b2642.tar.bz2
podman-4479b8eec3558daedfd519d577bf63a17f4b2642.zip
implement cp reads tar file from stdin/stdout
enables podman cp uses - to stream a tar archive from STDIN or to STDOUT. Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/e2e/cp_test.go75
1 files changed, 45 insertions, 30 deletions
diff --git a/test/e2e/cp_test.go b/test/e2e/cp_test.go
index 591f533d6..273668f35 100644
--- a/test/e2e/cp_test.go
+++ b/test/e2e/cp_test.go
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "strings"
. "github.com/containers/libpod/test/utils"
. "github.com/onsi/ginkgo"
@@ -58,21 +59,12 @@ var _ = Describe("Podman cp", func() {
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- session = podmanTest.Podman([]string{"start", "-a", name})
- session.WaitWithDefaultTimeout()
-
- Expect(session.ExitCode()).To(Equal(0))
- Expect(session.OutputToString()).To(Equal("copy from host to container"))
-
session = podmanTest.Podman([]string{"cp", name + ":foo", filepath.Join(path, "cp_from_container")})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- c := exec.Command("cat", filepath.Join(path, "cp_from_container"))
- output, err := c.Output()
- if err != nil {
- os.Exit(1)
- }
- Expect(string(output)).To(Equal("copy from host to container"))
+
+ os.Remove("cp_from_container")
+ os.Remove("cp_test.txt")
})
It("podman cp file to dir", func() {
@@ -89,28 +81,18 @@ var _ = Describe("Podman cp", func() {
session := podmanTest.Podman([]string{"create", ALPINE, "ls", "foodir/"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- session = podmanTest.Podman([]string{"ps", "-a", "-q"})
- session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
name := session.OutputToString()
session = podmanTest.Podman([]string{"cp", filepath.Join(path, "cp_test.txt"), name + ":foodir/"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- session = podmanTest.Podman([]string{"start", "-a", name})
- session.WaitWithDefaultTimeout()
- Expect(session.ExitCode()).To(Equal(0))
- Expect(session.OutputToString()).To(Equal("cp_test.txt"))
session = podmanTest.Podman([]string{"cp", name + ":foodir/cp_test.txt", path + "/receive/"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- c := exec.Command("cat", filepath.Join(path, "receive", "cp_test.txt"))
- output, err := c.Output()
- if err != nil {
- os.Exit(1)
- }
- Expect(string(output)).To(Equal("copy from host to container directory"))
+
+ os.Remove("cp_test.txt")
+ os.RemoveAll("receive")
})
It("podman cp dir to dir", func() {
@@ -132,17 +114,50 @@ var _ = Describe("Podman cp", func() {
session = podmanTest.Podman([]string{"cp", testDirPath, name + ":/foodir"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- session = podmanTest.Podman([]string{"start", "-a", name})
+
+ session = podmanTest.Podman([]string{"cp", testDirPath, name + ":/foodir"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- Expect(len(session.OutputToStringArray())).To(Equal(0))
- session = podmanTest.Podman([]string{"cp", testDirPath, name + ":/foodir"})
+ os.RemoveAll(testDirPath)
+ })
+
+ It("podman cp stdin/stdout", func() {
+ path, err := os.Getwd()
+ if err != nil {
+ os.Exit(1)
+ }
+ testDirPath := filepath.Join(path, "TestDir")
+ err = os.Mkdir(testDirPath, 0777)
+ if err != nil {
+ os.Exit(1)
+ }
+ cmd := exec.Command("tar", "-zcvf", "file.tar.gz", testDirPath)
+ _, err = cmd.Output()
+ if err != nil {
+ os.Exit(1)
+ }
+
+ session := podmanTest.Podman([]string{"create", ALPINE, "ls", "foo"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ name := session.OutputToString()
+
+ data, err := ioutil.ReadFile("foo.tar.gz")
+ reader := strings.NewReader(string(data))
+ cmd.Stdin = reader
+ session = podmanTest.Podman([]string{"cp", "-", name + ":/foo"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- session = podmanTest.Podman([]string{"start", "-a", name})
+
+ session = podmanTest.Podman([]string{"cp", "file.tar.gz", name + ":/foo.tar.gz"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
- Expect(session.OutputToString()).To(Equal("TestDir"))
+ session = podmanTest.Podman([]string{"cp", name + ":/foo.tar.gz", "-"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ os.Remove("file.tar.gz")
+ os.RemoveAll(testDirPath)
})
})