test: allow for testing all scenarios

Test all scenarios by default when running 'build' (which happens
when the script is called without arguments).

Default to scenario 'default' in other test commands like 'debug'.
This commit is contained in:
Erik Arvstedt 2020-08-21 22:36:13 +02:00
parent 28236691aa
commit 91697b1427
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
2 changed files with 30 additions and 32 deletions

View File

@ -4,51 +4,34 @@
# The test (./test.nix) uses the NixOS testing framework and is executed in a VM.
#
# Usage:
# Run test
# Run all tests
# ./run-tests.sh
#
# Test specific scenario
# ./run-tests.sh --scenario <scenario>
#
# Run test and save result to avoid garbage collection
# ./run-tests.sh --scenario <scenario> build --out-link /tmp/nix-bitcoin-test
# ./run-tests.sh [--scenario <scenario>] build --out-link /tmp/nix-bitcoin-test
#
# Run interactive test debugging
# ./run-tests.sh --scenario <scenario> debug
# ./run-tests.sh [--scenario <scenario>] debug
#
# This starts the testing VM and drops you into a Python REPL where you can
# manually execute the tests from ./test-script.py
set -eo pipefail
die() {
printf '%s\n' "$1" >&2
exit 1
}
# Initialize all the option variables.
# This ensures we are not contaminated by variables from the environment.
scenario=
while :; do
case $1 in
--scenario)
if [ "$2" ]; then
if [[ $1 == --scenario ]]; then
if [[ $2 ]]; then
scenario=$2
shift
else
die 'ERROR: "--scenario" requires a non-empty option argument.'
fi
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*)
break
esac
shift
done
if [[ -z $scenario ]]; then
die 'ERROR: "--scenario" is required'
else
>&2 echo 'Error: "--scenario" requires an argument.'
exit 1
fi
fi
numCPUs=${numCPUs:-$(nproc)}
@ -108,7 +91,7 @@ debug() {
}
# Run the test by building the test derivation
build() {
buildTest() {
vmTestNixExpr | nix-build --no-out-link "$@" -
}
@ -137,4 +120,18 @@ vmTestNixExpr() {
EOF
}
build() {
if [[ $scenario ]]; then
buildTest "$@"
else
scenario=default buildTest "$@"
scenario=withnetns buildTest "$@"
fi
}
# Set default scenario for all actions other than 'build'
if [[ $1 && $1 != build ]]; then
: ${scenario:=default}
fi
eval "${@:-build}"

View File

@ -1,5 +1,6 @@
# Integration test, can be run without internet access.
# Make sure to update build() in ./run-tests.sh when adding new scenarios
{ scenario ? "default" }:
import ./make-test.nix rec {