#!/bin/sh

# This script installs test dependencies and runs all tests, including end-to-end tests. It
# is designed to run inside a test container, and presumes that other test infrastructure like
# databases are already running. Therefore, on a developer machine, you should not run this script
# directly. Instead, run scripts/run-end-to-end-tests
#
# For more information, see:
# https://torsion.org/borgmatic/how-to/develop-on-borgmatic/

set -e

if [ -z "$TEST_CONTAINER" ]; then
    echo "This script is designed to work inside a test container and is not intended to"
    echo "be run manually. If you're trying to run borgmatic's end-to-end tests, execute"
    echo "scripts/run-end-to-end-dev-tests instead."
    exit 1
fi

apk add --no-cache python3 py3-pip borgbackup postgresql17-client mariadb-client mongodb-tools \
    py3-mongo py3-regex py3-ruamel.yaml py3-ruamel.yaml.clib py3-tox py3-yaml ruff sqlite uv bash \
    fish
export SHELL=/bin/bash
export PATH="/root/.local/bin:$PATH"
uv tool install tox --with tox-uv
export COVERAGE_FILE=/tmp/.coverage

tox --workdir /tmp/.tox -e py311,py314 --sitepackages
tox --workdir /tmp/.tox --sitepackages -e end-to-end
