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:
parent
28236691aa
commit
91697b1427
@ -4,51 +4,34 @@
|
|||||||
# The test (./test.nix) uses the NixOS testing framework and is executed in a VM.
|
# The test (./test.nix) uses the NixOS testing framework and is executed in a VM.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# Run test
|
# Run all tests
|
||||||
|
# ./run-tests.sh
|
||||||
|
#
|
||||||
|
# Test specific scenario
|
||||||
# ./run-tests.sh --scenario <scenario>
|
# ./run-tests.sh --scenario <scenario>
|
||||||
#
|
#
|
||||||
# Run test and save result to avoid garbage collection
|
# 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 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
|
# This starts the testing VM and drops you into a Python REPL where you can
|
||||||
# manually execute the tests from ./test-script.py
|
# manually execute the tests from ./test-script.py
|
||||||
|
|
||||||
set -eo pipefail
|
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=
|
scenario=
|
||||||
|
|
||||||
while :; do
|
if [[ $1 == --scenario ]]; then
|
||||||
case $1 in
|
if [[ $2 ]]; then
|
||||||
--scenario)
|
|
||||||
if [ "$2" ]; then
|
|
||||||
scenario=$2
|
scenario=$2
|
||||||
shift
|
shift
|
||||||
else
|
|
||||||
die 'ERROR: "--scenario" requires a non-empty option argument.'
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
-?*)
|
|
||||||
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
break
|
|
||||||
esac
|
|
||||||
|
|
||||||
shift
|
shift
|
||||||
done
|
else
|
||||||
|
>&2 echo 'Error: "--scenario" requires an argument.'
|
||||||
if [[ -z $scenario ]]; then
|
exit 1
|
||||||
die 'ERROR: "--scenario" is required'
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
numCPUs=${numCPUs:-$(nproc)}
|
numCPUs=${numCPUs:-$(nproc)}
|
||||||
@ -108,7 +91,7 @@ debug() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run the test by building the test derivation
|
# Run the test by building the test derivation
|
||||||
build() {
|
buildTest() {
|
||||||
vmTestNixExpr | nix-build --no-out-link "$@" -
|
vmTestNixExpr | nix-build --no-out-link "$@" -
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,4 +120,18 @@ vmTestNixExpr() {
|
|||||||
EOF
|
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}"
|
eval "${@:-build}"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# Integration test, can be run without internet access.
|
# Integration test, can be run without internet access.
|
||||||
|
|
||||||
|
# Make sure to update build() in ./run-tests.sh when adding new scenarios
|
||||||
{ scenario ? "default" }:
|
{ scenario ? "default" }:
|
||||||
|
|
||||||
import ./make-test.nix rec {
|
import ./make-test.nix rec {
|
||||||
|
Loading…
Reference in New Issue
Block a user