6
"github.com/containers/podman/v5/pkg/api/handlers"
7
"github.com/containers/podman/v5/pkg/bindings/containers"
8
. "github.com/onsi/ginkgo/v2"
9
. "github.com/onsi/gomega"
10
"github.com/onsi/gomega/gexec"
13
var _ = Describe("Podman containers exec", func() {
21
bt.RestoreImagesFromCache()
22
s = bt.startAPIService()
23
time.Sleep(1 * time.Second)
24
err := bt.NewConnection()
25
Expect(err).ToNot(HaveOccurred())
33
It("Podman exec create+start makes an exec session", func() {
35
cid, err := bt.RunTopContainer(&name, nil)
36
Expect(err).ToNot(HaveOccurred())
38
execConfig := new(handlers.ExecCreateConfig)
39
execConfig.Cmd = []string{"echo", "hello world"}
41
sessionID, err := containers.ExecCreate(bt.conn, name, execConfig)
42
Expect(err).ToNot(HaveOccurred())
43
Expect(sessionID).To(Not(Equal("")))
45
inspectOut, err := containers.ExecInspect(bt.conn, sessionID, nil)
46
Expect(err).ToNot(HaveOccurred())
47
Expect(inspectOut.ContainerID).To(Equal(cid))
48
Expect(inspectOut.ProcessConfig.Entrypoint).To(Equal("echo"))
49
Expect(inspectOut.ProcessConfig.Arguments).To(HaveLen(1))
50
Expect(inspectOut.ProcessConfig.Arguments[0]).To(Equal("hello world"))
52
err = containers.ExecStart(bt.conn, sessionID, nil)
53
Expect(err).ToNot(HaveOccurred())
55
inspectOut, err = containers.ExecInspect(bt.conn, sessionID, nil)
56
Expect(err).ToNot(HaveOccurred())
57
Expect(inspectOut.ContainerID).To(Equal(cid))
58
Expect(inspectOut.Running).To(BeFalse(), "session should not be running")
59
Expect(inspectOut.ExitCode).To(Equal(0), "exit code from echo")
62
It("Podman exec create with bad command fails", func() {
64
_, err := bt.RunTopContainer(&name, nil)
65
Expect(err).ToNot(HaveOccurred())
67
execConfig := new(handlers.ExecCreateConfig)
69
_, err = containers.ExecCreate(bt.conn, name, execConfig)
70
Expect(err).To(HaveOccurred())
73
It("Podman exec create with invalid container fails", func() {
74
execConfig := new(handlers.ExecCreateConfig)
75
execConfig.Cmd = []string{"echo", "hello world"}
77
_, err := containers.ExecCreate(bt.conn, "doesnotexist", execConfig)
78
Expect(err).To(HaveOccurred())
81
It("Podman exec inspect on invalid session fails", func() {
82
_, err := containers.ExecInspect(bt.conn, "0000000000000000000000000000000000000000000000000000000000000000", nil)
83
Expect(err).To(HaveOccurred())