github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/bindings/test/exec_test.go (about) 1 package test_bindings 2 3 import ( 4 "time" 5 6 "github.com/containers/podman/v2/pkg/api/handlers" 7 "github.com/containers/podman/v2/pkg/bindings" 8 "github.com/containers/podman/v2/pkg/bindings/containers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("Podman containers exec", func() { 15 var ( 16 bt *bindingTest 17 s *gexec.Session 18 ) 19 20 BeforeEach(func() { 21 bt = newBindingTest() 22 bt.RestoreImagesFromCache() 23 s = bt.startAPIService() 24 time.Sleep(1 * time.Second) 25 err := bt.NewConnection() 26 Expect(err).To(BeNil()) 27 }) 28 29 AfterEach(func() { 30 s.Kill() 31 bt.cleanup() 32 }) 33 34 It("Podman exec create makes an exec session", func() { 35 name := "testCtr" 36 cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil) 37 Expect(err).To(BeNil()) 38 39 execConfig := new(handlers.ExecCreateConfig) 40 execConfig.Cmd = []string{"echo", "hello world"} 41 42 sessionID, err := containers.ExecCreate(bt.conn, name, execConfig) 43 Expect(err).To(BeNil()) 44 Expect(sessionID).To(Not(Equal(""))) 45 46 inspectOut, err := containers.ExecInspect(bt.conn, sessionID) 47 Expect(err).To(BeNil()) 48 Expect(inspectOut.ContainerID).To(Equal(cid)) 49 Expect(inspectOut.ProcessConfig.Entrypoint).To(Equal("echo")) 50 Expect(len(inspectOut.ProcessConfig.Arguments)).To(Equal(1)) 51 Expect(inspectOut.ProcessConfig.Arguments[0]).To(Equal("hello world")) 52 }) 53 54 It("Podman exec create with bad command fails", func() { 55 name := "testCtr" 56 _, err := bt.RunTopContainer(&name, bindings.PFalse, nil) 57 Expect(err).To(BeNil()) 58 59 execConfig := new(handlers.ExecCreateConfig) 60 61 _, err = containers.ExecCreate(bt.conn, name, execConfig) 62 Expect(err).To(Not(BeNil())) 63 }) 64 65 It("Podman exec create with invalid container fails", func() { 66 execConfig := new(handlers.ExecCreateConfig) 67 execConfig.Cmd = []string{"echo", "hello world"} 68 69 _, err := containers.ExecCreate(bt.conn, "doesnotexist", execConfig) 70 Expect(err).To(Not(BeNil())) 71 }) 72 73 It("Podman exec inspect on invalid session fails", func() { 74 _, err := containers.ExecInspect(bt.conn, "0000000000000000000000000000000000000000000000000000000000000000") 75 Expect(err).To(Not(BeNil())) 76 }) 77 })