Merge pull request #5643 from edsantiago/test_apiv2

API v2 tests: usability improvements
This commit is contained in:
OpenShift Merge Robot
2020-03-30 16:51:58 +02:00
committed by GitHub
3 changed files with 39 additions and 17 deletions

View File

@ -11,7 +11,7 @@ podman pull $IMAGE &>/dev/null
# Ensure clean slate # Ensure clean slate
podman rm -a -f &>/dev/null podman rm -a -f &>/dev/null
t GET libpod/containers/json 200 length=0 t GET "libpod/containers/json (at start: clean slate)" 200 length=0
podman run $IMAGE true podman run $IMAGE true

View File

@ -3,7 +3,8 @@
# test pod-related endpoints # test pod-related endpoints
# #
t GET libpod/pods/json 200 null t GET "libpod/pods/json (clean slate at start)" 200 null
t POST libpod/pods/create name=foo 201 .id~[0-9a-f]\\{64\\} t POST libpod/pods/create name=foo 201 .id~[0-9a-f]\\{64\\}
pod_id=$(jq -r .id <<<"$output") pod_id=$(jq -r .id <<<"$output")
t GET libpod/pods/foo/exists 204 t GET libpod/pods/foo/exists 204
@ -19,7 +20,8 @@ t GET libpod/pods/json 200 \
.[0].Containers\|length=1 .[0].Containers\|length=1
# Cannot create a dup pod with the same name # Cannot create a dup pod with the same name
t POST libpod/pods/create name=foo 409 .cause="pod already exists" t POST "libpod/pods/create (dup pod)" name=foo 409 \
.cause="pod already exists"
#t POST libpod/pods/create a=b 400 .cause='bad parameter' # FIXME: unimplemented #t POST libpod/pods/create a=b 400 .cause='bad parameter' # FIXME: unimplemented
@ -27,16 +29,18 @@ if root || have_cgroupsv2; then
t POST libpod/pods/foo/pause '' 200 t POST libpod/pods/foo/pause '' 200
else else
# Rootless cgroupsv1 : unsupported # Rootless cgroupsv1 : unsupported
t POST libpod/pods/foo/pause '' 500 \ t POST "libpod/pods/foo/pause (rootless cgroups v1)" '' 500 \
.cause="this container does not have a cgroup" \ .cause="this container does not have a cgroup" \
.message~".*pause pods containing rootless containers with cgroup V1" .message~".*pause pods containing rootless containers with cgroup V1"
fi fi
t POST libpod/pods/foo/unpause '' 200 t POST libpod/pods/foo/unpause '' 200
t POST libpod/pods/foo/unpause '' 200 # (2nd time) t POST "libpod/pods/foo/unpause (2nd unpause in a row)" '' 200
t POST libpod/pods/foo/stop '' 304 t POST "libpod/pods/foo/stop (pod is already stopped)" '' 304
t POST libpod/pods/foo/restart '' 200 t POST libpod/pods/foo/restart '' 200 \
.Errs=null \
.Id=$pod_id
t POST libpod/pods/bar/restart '' 404 t POST "libpod/pods/bar/restart (restart on nonexistent pod)" '' 404
# FIXME: I'm not sure what 'prune' is supposed to do; as of 20200224 it # FIXME: I'm not sure what 'prune' is supposed to do; as of 20200224 it
# just returns 200 (ok) with empty result list. # just returns 200 (ok) with empty result list.
@ -44,7 +48,7 @@ t POST libpod/pods/bar/restart '' 404
#t POST libpod/pods/prune 'a=b' 400 # FIXME: 2020-02-24 returns 200 #t POST libpod/pods/prune 'a=b' 400 # FIXME: 2020-02-24 returns 200
# Clean up; and try twice, making sure that the second time fails # Clean up; and try twice, making sure that the second time fails
t DELETE libpod/pods/foo 200 t DELETE libpod/pods/foo 200
t DELETE libpod/pods/foo 404 t DELETE "libpod/pods/foo (pod has already been deleted)" 404
# vim: filetype=sh # vim: filetype=sh

View File

@ -24,8 +24,10 @@ IMAGE=$PODMAN_TEST_IMAGE_FQN
TMPDIR=${TMPDIR:-/tmp} TMPDIR=${TMPDIR:-/tmp}
WORKDIR=$(mktemp --tmpdir -d $ME.tmp.XXXXXX) WORKDIR=$(mktemp --tmpdir -d $ME.tmp.XXXXXX)
# Log of all HTTP requests and responses # Log of all HTTP requests and responses; always make '.log' point to latest
LOG=${TMPDIR}/$ME.log.$(date +'%Y%m%dT%H%M%S') LOGBASE=${TMPDIR}/$ME.log
LOG=${LOGBASE}.$(date +'%Y%m%dT%H%M%S')
ln -sf $LOG $LOGBASE
HOST=localhost HOST=localhost
PORT=${PODMAN_SERVICE_PORT:-8081} PORT=${PODMAN_SERVICE_PORT:-8081}
@ -110,17 +112,21 @@ function _show_ok() {
_bump $testcounter_file _bump $testcounter_file
count=$(<$testcounter_file) count=$(<$testcounter_file)
if [ $ok -eq 1 ]; then if [ $ok -eq 1 ]; then
echo -e "${green}ok $count $testname${reset}" echo -e "${green}ok $count ${TEST_CONTEXT} $testname${reset}"
echo "ok $count ${TEST_CONTEXT} $testname" >>$LOG
return return
fi fi
# Failed # Failed
local expect=$3 local expect=$3
local actual=$4 local actual=$4
echo -e "${red}not ok $count $testname${reset}" echo -e "${red}not ok $count ${TEST_CONTEXT} $testname${reset}"
echo -e "${red}# expected: $expect${reset}" echo -e "${red}# expected: $expect${reset}"
echo -e "${red}# actual: ${bold}$actual${reset}" echo -e "${red}# actual: ${bold}$actual${reset}"
echo "not ok $count ${TEST_CONTEXT} $testname" >>$LOG
echo " expected: $expect"
_bump $failures_file _bump $failures_file
} }
@ -168,6 +174,10 @@ function t() {
testname="$testname [$1]" testname="$testname [$1]"
shift shift
fi fi
# entrypoint path can include a descriptive comment; strip it off
path=${path%% *}
# curl -X HEAD but without --head seems to wait for output anyway # curl -X HEAD but without --head seems to wait for output anyway
if [[ $method == "HEAD" ]]; then if [[ $method == "HEAD" ]]; then
curl_args="--head" curl_args="--head"
@ -196,13 +206,20 @@ function t() {
exit 1 exit 1
fi fi
cat $WORKDIR/curl.headers.out $WORKDIR/curl.result.out >>$LOG 2>/dev/null || true cat $WORKDIR/curl.headers.out >>$LOG 2>/dev/null || true
output=$(< $WORKDIR/curl.result.out)
# Log results. If JSON, filter through jq for readability
if egrep -qi '^Content-Type: application/json' $WORKDIR/curl.headers.out; then
jq . <<<"$output" >>$LOG
else
echo "$output" >>$LOG
fi
# Test return code # Test return code
actual_code=$(head -n1 $WORKDIR/curl.headers.out | awk '/^HTTP/ { print $2}') actual_code=$(head -n1 $WORKDIR/curl.headers.out | awk '/^HTTP/ { print $2}')
is "$actual_code" "$expected_code" "$testname : status" is "$actual_code" "$expected_code" "$testname : status"
output=$(< $WORKDIR/curl.result.out)
# Special case: 204/304, by definition, MUST NOT return content (rfc2616) # Special case: 204/304, by definition, MUST NOT return content (rfc2616)
if [[ $expected_code = 204 || $expected_code = 304 ]]; then if [[ $expected_code = 204 || $expected_code = 304 ]]; then
@ -327,6 +344,7 @@ fi
start_service start_service
for i in ${tests_to_run[@]}; do for i in ${tests_to_run[@]}; do
TEST_CONTEXT="[$(basename $i .at)]"
source $i source $i
done done