From 4479b8eec3558daedfd519d577bf63a17f4b2642 Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Fri, 26 Apr 2019 17:27:06 -0400 Subject: 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 --- test/e2e/cp_test.go | 75 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 30 deletions(-) (limited to 'test') 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) }) }) -- cgit v1.2.3-54-g00ecf