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