Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #772 from devimc/topic/dockercpAndDev
Browse files Browse the repository at this point in the history
integration/docker: Add test to check host's integrity after `docker cp`
  • Loading branch information
grahamwhaley authored Sep 26, 2018
2 parents 734b167 + 65f9b1f commit d72794e
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions integration/docker/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path"

"github.com/kata-containers/tests"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -50,3 +51,53 @@ var _ = Describe("docker cp", func() {
})
})
})

var _ = Describe("docker cp with volume attached", func() {
var (
id string
exitCode int
hostPath string
cmd *tests.Command
dirBeforeCp string
dirAfterCp string
)

BeforeEach(func() {
hostPath = "/dev"
id = randomDockerName()
})

AfterEach(func() {
Expect(ExistDockerContainer(id)).NotTo(BeTrue())
})

Context("check host path integrity", func() {
It("should not be modified", func() {
file, err := ioutil.TempFile(os.TempDir(), "file")
Expect(err).ToNot(HaveOccurred())
err = file.Close()
Expect(err).ToNot(HaveOccurred())
defer os.Remove(file.Name())
Expect(file.Name()).To(BeAnExistingFile())

// check hostPath before running docker cp
cmd = tests.NewCommand("ls", hostPath)
dirBeforeCp, _, exitCode = cmd.Run()
Expect(exitCode).To(BeZero())

_, _, exitCode = dockerRun("-td", "-v", hostPath+":"+hostPath, "--name", id, Image, "sh")
Expect(exitCode).To(Equal(0))
_, _, exitCode = dockerCp(file.Name(), id+":/")
Expect(exitCode).To(BeZero())
Expect(RemoveDockerContainer(id)).To(BeTrue())

// check hostPath after running docker cp
cmd = tests.NewCommand("ls", hostPath)
dirAfterCp, _, exitCode = cmd.Run()
Expect(exitCode).To(BeZero())

// hostPath files and directories should be the same
Expect(dirBeforeCp).To(Equal(dirAfterCp))
})
})
})

0 comments on commit d72794e

Please sign in to comment.