Skip to content

Commit

Permalink
Merge pull request containers#10371 from matejvasek/fix-wait-compat
Browse files Browse the repository at this point in the history
fix: response of containers wait endpoint
  • Loading branch information
openshift-merge-robot authored May 19, 2021
2 parents 4002589 + 92e8589 commit 18efc5a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/api/handlers/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type BuildResult struct {

type ContainerWaitOKBody struct {
StatusCode int
Error struct {
Error *struct {
Message string
}
}
Expand Down
15 changes: 8 additions & 7 deletions pkg/api/handlers/utils/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,19 @@ func WaitContainerDocker(w http.ResponseWriter, r *http.Request) {
}

exitCode, err := waitDockerCondition(ctx, name, interval, condition)
msg := ""
var errStruct *struct{ Message string }
if err != nil {
logrus.Errorf("error while waiting on condition: %q", err)
msg = err.Error()
errStruct = &struct {
Message string
}{
Message: err.Error(),
}
}

responseData := handlers.ContainerWaitOKBody{
StatusCode: int(exitCode),
Error: struct {
Message string
}{
Message: msg,
},
Error: errStruct,
}
enc := json.NewEncoder(w)
enc.SetEscapeHTML(true)
Expand Down
4 changes: 3 additions & 1 deletion test/apiv2/26-containersWait.at
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ t POST "containers/${CTR}/wait?condition=non-existent-cond" 400

t POST "containers/${CTR}/wait?condition=not-running" 200

t POST "containers/${CTR}/wait?condition=next-exit" 200 &
t POST "containers/${CTR}/wait?condition=next-exit" 200 \
.StatusCode=0 \
.Error=null &
child_pid=$!
podman start "${CTR}"
wait "${child_pid}"
Expand Down
2 changes: 1 addition & 1 deletion test/apiv2/python/rest_api/test_v2_0_0_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_prune(self):
r = requests.post(self.podman_url + f"/v1.40/containers/{create['Id']}/wait")
self.assertEqual(r.status_code, 200, r.text)
wait = r.json()
self.assertEqual(wait["StatusCode"], 0, wait["Error"]["Message"])
self.assertEqual(wait["StatusCode"], 0, wait["Error"])

prune = requests.post(self.podman_url + "/v1.40/containers/prune")
self.assertEqual(prune.status_code, 200, prune.status_code)
Expand Down

0 comments on commit 18efc5a

Please sign in to comment.