github.com/containers/podman/v4@v4.9.4/test/e2e/run_working_dir_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 8 . "github.com/containers/podman/v4/test/utils" 9 . "github.com/onsi/ginkgo/v2" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("Podman run", func() { 15 16 It("podman run a container without workdir", func() { 17 session := podmanTest.Podman([]string{"run", ALPINE, "pwd"}) 18 session.WaitWithDefaultTimeout() 19 Expect(session).Should(ExitCleanly()) 20 Expect(session.OutputToString()).To(Equal("/")) 21 }) 22 23 It("podman run a container using non existing --workdir", func() { 24 session := podmanTest.Podman([]string{"run", "--workdir", "/home/foobar", ALPINE, "pwd"}) 25 session.WaitWithDefaultTimeout() 26 Expect(session).Should(Exit(126)) 27 }) 28 29 It("podman run a container using a --workdir under a bind mount", func() { 30 volume := filepath.Join(podmanTest.TempDir, "vol") 31 err = os.MkdirAll(volume, os.ModePerm) 32 Expect(err).ToNot(HaveOccurred()) 33 34 session := podmanTest.Podman([]string{"run", "--volume", fmt.Sprintf("%s:/var_ovl/:O", volume), "--workdir", "/var_ovl/log", ALPINE, "true"}) 35 session.WaitWithDefaultTimeout() 36 Expect(session).Should(ExitCleanly()) 37 }) 38 39 It("podman run a container on an image with a workdir", func() { 40 dockerfile := fmt.Sprintf(`FROM %s 41 RUN mkdir -p /home/foobar /etc/foobar; chown bin:bin /etc/foobar 42 WORKDIR /etc/foobar`, ALPINE) 43 podmanTest.BuildImage(dockerfile, "test", "false") 44 45 session := podmanTest.Podman([]string{"run", "test", "pwd"}) 46 session.WaitWithDefaultTimeout() 47 Expect(session).Should(ExitCleanly()) 48 Expect(session.OutputToString()).To(Equal("/etc/foobar")) 49 50 session = podmanTest.Podman([]string{"run", "test", "ls", "-ld", "."}) 51 session.WaitWithDefaultTimeout() 52 Expect(session.OutputToString()).To(ContainSubstring("bin")) 53 54 session = podmanTest.Podman([]string{"run", "--workdir", "/home/foobar", "test", "pwd"}) 55 session.WaitWithDefaultTimeout() 56 Expect(session).Should(ExitCleanly()) 57 Expect(session.OutputToString()).To(Equal("/home/foobar")) 58 }) 59 })