mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-10-28 08:47:39 +00:00
test/e2e: close and remove temp file before cp in cp_test
Close the temporary destination file and remove it before copying to avoid issues with copying to an existing open file. Store the filename in a variable for reuse and defer cleanup. Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com> Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
parent
75c7a0dd27
commit
07637f101b
1 changed files with 18 additions and 14 deletions
|
|
@ -72,12 +72,14 @@ var _ = Describe("Podman cp", func() {
|
|||
|
||||
// Copy FROM the container.
|
||||
|
||||
destFile, err := ioutil.TempFile("", "")
|
||||
Expect(err).To(BeNil())
|
||||
defer destFile.Close()
|
||||
defer os.Remove(destFile.Name())
|
||||
destFile, err := os.CreateTemp("", "")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
destFileName := destFile.Name()
|
||||
destFile.Close()
|
||||
os.Remove(destFileName)
|
||||
defer os.Remove(destFileName)
|
||||
|
||||
session = podmanTest.Podman([]string{"cp", name + ":foo", destFile.Name()})
|
||||
session = podmanTest.Podman([]string{"cp", name + ":foo", destFileName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
|
|
@ -86,8 +88,8 @@ var _ = Describe("Podman cp", func() {
|
|||
Expect(session).Should(Exit(0))
|
||||
|
||||
// Now make sure the content matches.
|
||||
roundtripContent, err := ioutil.ReadFile(destFile.Name())
|
||||
Expect(err).To(BeNil())
|
||||
roundtripContent, err := os.ReadFile(destFileName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(roundtripContent).To(Equal(originalContent))
|
||||
})
|
||||
|
||||
|
|
@ -121,18 +123,20 @@ var _ = Describe("Podman cp", func() {
|
|||
|
||||
// Copy FROM the container.
|
||||
|
||||
destFile, err := ioutil.TempFile("", "")
|
||||
Expect(err).To(BeNil())
|
||||
defer destFile.Close()
|
||||
defer os.Remove(destFile.Name())
|
||||
destFile, err := os.CreateTemp("", "")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
destFileName := destFile.Name()
|
||||
destFile.Close()
|
||||
os.Remove(destFileName)
|
||||
defer os.Remove(destFileName)
|
||||
|
||||
session = podmanTest.Podman([]string{"cp", name + ":foo", destFile.Name()})
|
||||
session = podmanTest.Podman([]string{"cp", name + ":foo", destFileName})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
// Now make sure the content matches.
|
||||
roundtripContent, err := ioutil.ReadFile(destFile.Name())
|
||||
Expect(err).To(BeNil())
|
||||
roundtripContent, err := os.ReadFile(destFileName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(roundtripContent).To(Equal(originalContent))
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue