github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/test/e2e/run_working_dir_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 "strings" 6 7 . "github.com/containers/podman/v2/test/utils" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Podman run", func() { 13 var ( 14 tempdir string 15 err error 16 podmanTest *PodmanTestIntegration 17 ) 18 19 BeforeEach(func() { 20 tempdir, err = CreateTempDirInTempDir() 21 if err != nil { 22 os.Exit(1) 23 } 24 podmanTest = PodmanTestCreate(tempdir) 25 podmanTest.Setup() 26 podmanTest.SeedImages() 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.ExitCode()).To(Equal(0)) 40 Expect(session.OutputToString()).To(Equal("/")) 41 }) 42 43 It("podman run a container using non existing --workdir", func() { 44 if !strings.Contains(podmanTest.OCIRuntime, "crun") { 45 Skip("Test only works on crun") 46 } 47 session := podmanTest.Podman([]string{"run", "--workdir", "/home/foobar", ALPINE, "pwd"}) 48 session.WaitWithDefaultTimeout() 49 Expect(session.ExitCode()).To(Equal(127)) 50 }) 51 52 It("podman run a container on an image with a workdir", func() { 53 dockerfile := `FROM alpine 54 RUN mkdir -p /home/foobar 55 WORKDIR /etc/foobar` 56 podmanTest.BuildImage(dockerfile, "test", "false") 57 58 session := podmanTest.Podman([]string{"run", "test", "pwd"}) 59 session.WaitWithDefaultTimeout() 60 Expect(session.ExitCode()).To(Equal(0)) 61 Expect(session.OutputToString()).To(Equal("/etc/foobar")) 62 63 session = podmanTest.Podman([]string{"run", "--workdir", "/home/foobar", "test", "pwd"}) 64 session.WaitWithDefaultTimeout() 65 Expect(session.ExitCode()).To(Equal(0)) 66 Expect(session.OutputToString()).To(Equal("/home/foobar")) 67 }) 68 })