summaryrefslogtreecommitdiff
path: root/test/apiv2/test-apiv2
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2021-12-14 13:44:39 -0700
committerEd Santiago <santiago@redhat.com>2021-12-14 18:28:50 -0700
commit7b51acd4c4140c6fe7f262936c0eee8db2f0cacb (patch)
treec49e2301d014aa6e1ad7fb4c3bddd6e55952a356 /test/apiv2/test-apiv2
parentb01a421f3413ba01b2c189b82c8153bdbd2a05fb (diff)
downloadpodman-7b51acd4c4140c6fe7f262936c0eee8db2f0cacb.tar.gz
podman-7b51acd4c4140c6fe7f262936c0eee8db2f0cacb.tar.bz2
podman-7b51acd4c4140c6fe7f262936c0eee8db2f0cacb.zip
APIv2 tests: fail on syntax/logic errors
(i.e. not test failures, but actual programming bugs). We've had a number of syntax errors creep into this test, usually caused by a missing backslash on a test command. I've long wanted to 'set -e' but that causes other problems. This PR introduces error handling via 'trap', with useful diagnostics on failure. This PR also catches and fixes two previously-unknown bugs that were causing tests to not actually run. And, since /events takes eons on my high-uptime laptop, add /since Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'test/apiv2/test-apiv2')
-rwxr-xr-xtest/apiv2/test-apiv255
1 files changed, 37 insertions, 18 deletions
diff --git a/test/apiv2/test-apiv2 b/test/apiv2/test-apiv2
index 47934cca9..391095539 100755
--- a/test/apiv2/test-apiv2
+++ b/test/apiv2/test-apiv2
@@ -48,6 +48,30 @@ TESTS_DIR=$(realpath $(dirname $0))
# Path to podman binary
PODMAN_BIN=${PODMAN:-${TESTS_DIR}/../../bin/podman}
+# Cleanup handlers
+clean_up_server() {
+ if [ -n "$service_pid" ]; then
+ # Remove any containers and images; this prevents the following warning:
+ # 'rm: cannot remove '/.../overlay': Device or resource busy
+ podman rm -a
+ podman rmi -af
+
+ stop_registry
+ stop_service
+ fi
+}
+
+# Any non-test-related error, be it syntax or podman-command, fails here.
+err_handler() {
+ echo "Fatal error in ${BASH_SOURCE[1]}:${BASH_LINENO[0]}"
+ echo "Log:"
+ sed -e 's/^/ >/' <$WORKDIR/output.log
+ echo "Bailing."
+ clean_up_server
+}
+
+trap err_handler ERR
+
# END setup
###############################################################################
# BEGIN infrastructure code - the helper functions used in tests themselves
@@ -237,14 +261,15 @@ function t() {
echo "\$ $testname" >>$LOG
rm -f $WORKDIR/curl.*
# -s = silent, but --write-out 'format' gives us important response data
- response=$(curl -s -X $method ${curl_args} \
+ # The hairy "{ ...;rc=$?; } || :" lets us capture curl's exit code and
+ # give a helpful diagnostic if it fails.
+ { response=$(curl -s -X $method ${curl_args} \
-H "Content-type: $content_type" \
- --dump-header $WORKDIR/curl.headers.out \
+ --dump-header $WORKDIR/curl.headers.out \
--write-out '%{http_code}^%{content_type}^%{time_total}' \
- -o $WORKDIR/curl.result.out "$url")
+ -o $WORKDIR/curl.result.out "$url"); rc=$?; } || :
# Any error from curl is instant bad news, from which we can't recover
- rc=$?
if [[ $rc -ne 0 ]]; then
echo "FATAL: curl failure ($rc) on $url - cannot continue" >&2
exit 1
@@ -353,8 +378,8 @@ function start_service() {
function stop_service() {
# Stop the server
if [[ -n $service_pid ]]; then
- kill $service_pid
- wait $service_pid
+ kill $service_pid || :
+ wait $service_pid || :
fi
}
@@ -471,7 +496,7 @@ function wait_for_port() {
# podman # Needed by some test scripts to invoke the actual podman binary
############
function podman() {
- echo "\$ $PODMAN_BIN $*" >>$WORKDIR/output.log
+ echo "\$ $PODMAN_BIN $*" >>$WORKDIR/output.log
env CONTAINERS_REGISTRIES_CONF=$TESTS_DIR/../registries.conf \
$PODMAN_BIN --root $WORKDIR/server_root "$@" >>$WORKDIR/output.log 2>&1
}
@@ -529,23 +554,17 @@ start_service
for i in ${tests_to_run[@]}; do
TEST_CONTEXT="[$(basename $i .at)]"
+
+ # Clear output from 'podman' helper
+ >| $WORKDIR/output.log
+
source $i
done
# END entry handler
###############################################################################
-# Clean up
-
-if [ -n "$service_pid" ]; then
- # Remove any containers and images; this prevents the following warning:
- # 'rm: cannot remove '/.../overlay': Device or resource busy
- podman rm -a
- podman rmi -af
-
- stop_registry
- stop_service
-fi
+clean_up_server
test_count=$(<$testcounter_file)
failure_count=$(<$failures_file)