github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/run_working_dir_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "os" 6 7 . "github.com/hanks177/podman/v4/test/utils" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("Podman run", func() { 14 var ( 15 tempdir string 16 err error 17 podmanTest *PodmanTestIntegration 18 ) 19 20 BeforeEach(func() { 21 tempdir, err = CreateTempDirInTempDir() 22 if err != nil { 23 os.Exit(1) 24 } 25 podmanTest = PodmanTestCreate(tempdir) 26 podmanTest.Setup() 27 }) 28 29 AfterEach(func() { 30 podmanTest.Cleanup() 31 f := CurrentGinkgoTestDescription() 32 processTestResult(f) 33 34 }) 35 36 It("podman run a container without workdir", func() { 37 session := podmanTest.Podman([]string{"run", ALPINE, "pwd"}) 38 session.WaitWithDefaultTimeout() 39 Expect(session).Should(Exit(0)) 40 Expect(session.OutputToString()).To(Equal("/")) 41 }) 42 43 It("podman run a container using non existing --workdir", func() { 44 session := podmanTest.Podman([]string{"run", "--workdir", "/home/foobar", ALPINE, "pwd"}) 45 session.WaitWithDefaultTimeout() 46 Expect(session).Should(Exit(126)) 47 }) 48 49 It("podman run a container on an image with a workdir", func() { 50 dockerfile := fmt.Sprintf(`FROM %s 51 RUN mkdir -p /home/foobar /etc/foobar; chown bin:bin /etc/foobar 52 WORKDIR /etc/foobar`, ALPINE) 53 podmanTest.BuildImage(dockerfile, "test", "false") 54 55 session := podmanTest.Podman([]string{"run", "test", "pwd"}) 56 session.WaitWithDefaultTimeout() 57 Expect(session).Should(Exit(0)) 58 Expect(session.OutputToString()).To(Equal("/etc/foobar")) 59 60 session = podmanTest.Podman([]string{"run", "test", "ls", "-ld", "."}) 61 session.WaitWithDefaultTimeout() 62 Expect(session.OutputToString()).To(ContainSubstring("bin")) 63 64 session = podmanTest.Podman([]string{"run", "--workdir", "/home/foobar", "test", "pwd"}) 65 session.WaitWithDefaultTimeout() 66 Expect(session).Should(Exit(0)) 67 Expect(session.OutputToString()).To(Equal("/home/foobar")) 68 }) 69 })