# This test runs the mitm.py Flask app which debootstrap is then pointed at.
# mitm.py will return a Packages file which has an additional `apt` stanza
# prepended, with the Version and Filename adjusted to point at a lower,
# non-existent version.  Versions of debootstrap which process _all_ Packages
# files entries will find the original stanza later in the file (and
# succesfully fetch the corresponding package file): versions that don't will
# find the prepended stanza and fail (with a 404 of the nonexistent package
# file).

export FLASK_ARCH=amd64
export FLASK_DIST=bookworm
export FLASK_DISTRO=debian
export FLASK_MIRROR=http://deb.debian.org

# Launch our MitM "mirror" server, ensure that request logging is sent to stdout
(cd debian/tests; FLASK_APP=mitm.py flask run 2>&1 &)

# Give Flask time to come up
sleep 2

# Run debootstrap against our MitM "mirror", ignoring the inevitable GPG errors
debootstrap --variant minbase --no-check-gpg ${FLASK_DIST} bootstrap http://127.0.0.1:5000/${FLASK_DISTRO}/
