mirror of
https://github.com/containers/podman.git
synced 2025-08-02 17:22:30 +08:00
Merge pull request #3041 from QiWang19/cpdash
implement cp reads tar file from stdin/to stdout
This commit is contained in:
@ -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.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(len(session.OutputToStringArray())).To(Equal(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"cp", testDirPath, name + ":/foodir"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
session = podmanTest.Podman([]string{"start", "-a", name})
|
||||
|
||||
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))
|
||||
Expect(session.OutputToString()).To(Equal("TestDir"))
|
||||
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{"cp", "file.tar.gz", name + ":/foo.tar.gz"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user