#!/bin/bash

set -e

arch="$(dpkg --print-architecture)"
case $arch in
	amd64|arm64|armel|armhf|i386|mips64el|mipsel|ppc64el|s390x)
		;;
	*)
		echo "skipping: $arch not in bookworm" >&2
		exit 77
esac

if ! grep -qs ^debusine-worker: /etc/subuid; then
	# unshare needs /etc/subuid and /etc/subgid, and this is only set up
	# on our debusine-worker for >= bookworm (see
	# debusine-worker.postinst for more information)
	echo 'unshare-based tests require Debian >= bookworm' >&2
	exit 77  # tell autopkgtest to skip test
fi

debian/tests/utils/check-namespace-support

source debian/tests/utils/add-debusine-log-files-to-artifacts.sh

adduser debusine-worker sbuild

debian/tests/utils/integration-tests-setup-debusine-all.sh
debian/tests/utils/integration-tests-setup-debusine-signing.sh

# To make autopkgtest faster on salsa: use xz faster compression
mkdir /lib/systemd/system/debusine-worker.service.d/
(echo "[Service]" ; echo 'Environment="XZ_OPT=-0"') >> \
	/lib/systemd/system/debusine-worker.service.d/autopkgtest.conf
systemctl daemon-reload
systemctl restart debusine-worker

# The mmdebstrap test must run first to create environments used by the
# other tests.
pytest --rootdir=. -c /dev/null --durations=0 -v \
	debian/tests/integration-tests-task-mmdebstrap.py \
	debian/tests/integration-tests-workflow-debian-pipeline.py
