51 lines
1.6 KiB
Bash
Executable File
51 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# Run the emailwiz test suite in disposable Debian 13 systemd containers.
|
|
# usage: tests/run.sh [migration|clean|setup|certbot|all] (needs docker; builds the image)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
ROOT=$(pwd)
|
|
IMG=emailwiz-test:trixie
|
|
which=${1:-all}
|
|
|
|
echo "== static checks"
|
|
shellcheck -x -P lib emailwiz install.sh lib/*.sh templates/certbot-deploy-hook tests/*.sh
|
|
for f in emailwiz lib/*.sh; do sh -n "$f"; done
|
|
echo "shellcheck + sh -n: OK"
|
|
|
|
docker build -q -t "$IMG" -f tests/Containerfile tests >/dev/null
|
|
|
|
run_scenario() {
|
|
name=$1
|
|
cid=$(docker run -d --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw \
|
|
--hostname mx1 --tmpfs /run --tmpfs /run/lock \
|
|
-v "$ROOT:/src:ro" "$IMG")
|
|
trap 'docker rm -f "$cid" >/dev/null 2>&1 || :' EXIT
|
|
# wait for systemd
|
|
i=0
|
|
until docker exec "$cid" systemctl is-system-running 2>/dev/null | grep -Eq 'running|degraded'; do
|
|
i=$((i + 1)); [ $i -gt 60 ] && { echo "systemd did not boot"; exit 1; }; sleep 1
|
|
done
|
|
rc=0
|
|
docker exec "$cid" sh /src/tests/in-container.sh "$name" || rc=$?
|
|
docker rm -f "$cid" >/dev/null
|
|
trap - EXIT
|
|
return $rc
|
|
}
|
|
|
|
fails=0
|
|
case $which in
|
|
migration | all) run_scenario migration || fails=$((fails + 1)) ;;
|
|
esac
|
|
case $which in
|
|
clean | all) run_scenario clean || fails=$((fails + 1)) ;;
|
|
esac
|
|
case $which in
|
|
setup | all) run_scenario setup || fails=$((fails + 1)) ;;
|
|
esac
|
|
case $which in
|
|
certbot | all) run_scenario certbot || fails=$((fails + 1)) ;;
|
|
esac
|
|
echo
|
|
[ $fails -eq 0 ] && echo "ALL SCENARIOS PASSED" || { echo "$fails SCENARIO(S) FAILED"; exit 1; }
|