aboutsummaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/containers/containers.go13
-rw-r--r--pkg/bindings/test/containers_test.go57
2 files changed, 66 insertions, 4 deletions
diff --git a/pkg/bindings/containers/containers.go b/pkg/bindings/containers/containers.go
index 337cc4178..670321f21 100644
--- a/pkg/bindings/containers/containers.go
+++ b/pkg/bindings/containers/containers.go
@@ -210,15 +210,20 @@ func Unpause(ctx context.Context, nameOrID string) error {
return response.Process(nil)
}
-// Wait blocks until the given container exits and returns its exit code. The nameOrID can be a container name
-// or a partial/full ID.
-func Wait(ctx context.Context, nameOrID string) (int32, error) {
+// Wait blocks until the given container reaches a condition. If not provided, the condition will
+// default to stopped. If the condition is stopped, an exit code for the container will be provided. The
+// nameOrID can be a container name or a partial/full ID.
+func Wait(ctx context.Context, nameOrID string, condition *string) (int32, error) {
var exitCode int32
conn, err := bindings.GetClient(ctx)
if err != nil {
return exitCode, err
}
- response, err := conn.DoRequest(nil, http.MethodPost, "containers/%s/wait", nil, nameOrID)
+ params := url.Values{}
+ if condition != nil {
+ params.Set("condition", *condition)
+ }
+ response, err := conn.DoRequest(nil, http.MethodPost, "/containers/%s/wait", params, nameOrID)
if err != nil {
return exitCode, err
}
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index 5a0bdebe6..299a78ac2 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -250,4 +250,61 @@ var _ = Describe("Podman containers ", func() {
Expect(isStopped(data.State.Status)).To(BeTrue())
})
+ It("podman wait no condition", func() {
+ var (
+ name = "top"
+ exitCode int32 = -1
+ )
+ _, err := containers.Wait(connText, "foobar", nil)
+ Expect(err).ToNot(BeNil())
+ code, _ := bindings.CheckResponseCode(err)
+ Expect(code).To(BeNumerically("==", http.StatusNotFound))
+
+ errChan := make(chan error)
+ bt.RunTopContainer(&name, nil, nil)
+ go func() {
+ exitCode, err = containers.Wait(connText, name, nil)
+ errChan <- err
+ close(errChan)
+ }()
+ err = containers.Stop(connText, name, nil)
+ Expect(err).To(BeNil())
+ wait := <-errChan
+ Expect(wait).To(BeNil())
+ Expect(exitCode).To(BeNumerically("==", 143))
+ })
+
+ It("podman wait to pause|unpause condition", func() {
+ var (
+ name = "top"
+ exitCode int32 = -1
+ pause = "paused"
+ unpause = "running"
+ )
+ errChan := make(chan error)
+ bt.RunTopContainer(&name, nil, nil)
+ go func() {
+ exitCode, err = containers.Wait(connText, name, &pause)
+ errChan <- err
+ close(errChan)
+ }()
+ err := containers.Pause(connText, name)
+ Expect(err).To(BeNil())
+ wait := <-errChan
+ Expect(wait).To(BeNil())
+ Expect(exitCode).To(BeNumerically("==", -1))
+
+ errChan = make(chan error)
+ go func() {
+ exitCode, err = containers.Wait(connText, name, &unpause)
+ errChan <- err
+ close(errChan)
+ }()
+ err = containers.Unpause(connText, name)
+ Expect(err).To(BeNil())
+ unPausewait := <-errChan
+ Expect(unPausewait).To(BeNil())
+ Expect(exitCode).To(BeNumerically("==", -1))
+ })
+
})