Files
podman/test/apiv2/26-containersWait.at
Matej Vasek 92e858914d fix: response body of containers wait endpoint
The `Error` part of response must be nil (or omitted) if no error occurred.
Before this commit a zero value for the struct was returned.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-05-18 20:52:09 +02:00

50 lines
1.1 KiB
Bash

# -*- sh -*-
#
# test more container-related endpoints
#
red='\e[31m'
nc='\e[0m'
podman pull "${IMAGE}" &>/dev/null
# Ensure clean slate
podman rm -a -f &>/dev/null
CTR="WaitTestingCtr"
t POST "containers/nonExistent/wait?condition=next-exit" 404
podman create --name "${CTR}" --entrypoint '["true"]' "${IMAGE}"
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 \
.StatusCode=0 \
.Error=null &
child_pid=$!
podman start "${CTR}"
wait "${child_pid}"
# check if headers are sent in advance before body
WAIT_TEST_ERROR=""
curl -I -X POST "http://$HOST:$PORT/containers/${CTR}/wait?condition=next-exit" &> "/dev/null" &
child_pid=$!
sleep 0.5
if kill -2 "${child_pid}" 2> "/dev/null"; then
echo -e "${red}NOK: Failed to get response headers immediately.${nc}" 1>&2;
WAIT_TEST_ERROR="1"
fi
t POST "containers/${CTR}/wait?condition=removed" 200 &
child_pid=$!
podman container rm "${CTR}"
wait "${child_pid}"
if [[ "${WAIT_TEST_ERROR}" ]] ; then
exit 1;
fi