summaryrefslogtreecommitdiff
path: root/test/apiv2/26-containersWait.at
blob: 3f530c3f0180df4439eee7743449e4cfb3c7017a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- 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 '["sleep", "0.5"]' "${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 &
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