Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compose tests to report test errors as failures #21046

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/compose/simple_port_map/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine
WORKDIR /app
RUN apk update && apk add py3-pip && pip3 install flask
RUN apk update && apk add py3-flask
gavinkflam marked this conversation as resolved.
Show resolved Hide resolved
COPY . /app
ENTRYPOINT ["python3"]
CMD ["app.py"]
2 changes: 1 addition & 1 deletion test/compose/slirp4netns_opts/teardown.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- bash -*-

kill $nc_pid &> /dev/null
kill $nc_pid &> /dev/null || true
rm -f $OUTFILE
30 changes: 22 additions & 8 deletions test/compose/test-compose
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Usage: test-compose [testname]
#
set -Eu
ME=$(basename $0)

###############################################################################
Expand Down Expand Up @@ -240,7 +241,10 @@ function podman() {
--runroot $WORKDIR/runroot \
--network-config-dir $WORKDIR/cni \
"$@")
rc=$?

echo -n "$output" >>$WORKDIR/output.log
return $rc
gavinkflam marked this conversation as resolved.
Show resolved Hide resolved
}

###################
Expand Down Expand Up @@ -300,8 +304,8 @@ for t in "${tests_to_run[@]}"; do
testdir="$(dirname $t)"
testname="$(basename $testdir)"

if [ -e $test_dir/SKIP ]; then
reason="$(<$test_dir/SKIP)"
if [ -e $testdir/SKIP ]; then
reason="$(<$testdir/SKIP)"
if [ -n "$reason" ]; then
reason=" - $reason"
fi
Expand All @@ -315,13 +319,21 @@ for t in "${tests_to_run[@]}"; do
(
cd $testdir || die "Cannot cd $testdir"

if [ -e teardown.sh ]; then
trap 'teardown' EXIT
function teardown() {
trap '_show_ok 0 "$testname - teardown" "[ok]" "[error]"' ERR
. teardown.sh
trap - ERR
}
fi

# setup file may be used for creating temporary directories/files.
# We source it so that envariables defined in it will get back to us.
if [ -e setup.sh ]; then
trap '_show_ok 0 "$testname - setup" "[ok]" "[error]"' ERR
. setup.sh
fi
if [ -e teardown.sh ]; then
trap '. teardown.sh' 0
trap - ERR
fi

podman compose up -d &> $logfile
Expand All @@ -337,11 +349,13 @@ for t in "${tests_to_run[@]}"; do
# Run tests. This is likely to be a series of 'test_port' checks
# but may also include podman commands to inspect labels, state
if [ -e tests.sh ]; then
trap '_show_ok 0 "$testname - tests" "[ok]" "[error]"' ERR
. tests.sh
trap - ERR
fi
# FIXME: if any tests fail, try 'podman logs' on container?

if [ -n "$COMPOSE_WAIT" ]; then
if [ -n "${COMPOSE_WAIT:-}" ]; then
echo -n "Pausing due to \$COMPOSE_WAIT. Press ENTER to continue: "
read keepgoing
fi
Expand Down Expand Up @@ -379,8 +393,8 @@ done
test_count=$(<$testcounter_file)
failure_count=$(<$failures_file)

if [ -z "$PODMAN_TESTS_KEEP_WORKDIR" ]; then
if ! is_rootless; then
if [ -z "${PODMAN_TESTS_KEEP_WORKDIR:-}" ]; then
if ! is_rootless; then
rm -rf $WORKDIR
else
$PODMAN_BIN unshare rm -rf $WORKDIR
Expand Down