57 lines
1.4 KiB
Bash
57 lines
1.4 KiB
Bash
|
#! /usr/bin/env bash
|
||
|
|
||
|
DEPENDENCIES=("nix" "nix-shell")
|
||
|
# TODO: find grep package name for --pure environment
|
||
|
NIX_DEPENDENCIES=("bats" "curl" "qbittorrent-nox")
|
||
|
|
||
|
if [[ "${QBTNOX_DIR:-plz}" = "plz" ]]; then
|
||
|
export QBTNOX_DIR="$(mktemp -d)"
|
||
|
fi
|
||
|
|
||
|
ORIGDIR="$(pwd)"
|
||
|
cd "$(dirname "$0")"
|
||
|
|
||
|
source ../utils.sh
|
||
|
|
||
|
SUBCOMMAND="${1:-test}"
|
||
|
|
||
|
# Ensure nix shell with bats and curl... if we are running tests
|
||
|
if [[ "$SUBCOMMAND" = "test" ]] && [[ "${IN_NIX_SHELL:-plz}" = "plz" ]]; then
|
||
|
# Did test.sh perform depsCheck already?
|
||
|
if [[ "${TESTRUNNER:-plz}" = "plz" ]]; then
|
||
|
depsCheck
|
||
|
fi
|
||
|
# Are we in nix-shell already?
|
||
|
# TODO: redo --pure when grep dep is found
|
||
|
IN_NIX_SHELL=1 nix-shell -p ${NIX_DEPENDENCIES[@]} --run "\"$ORIGDIR\"/\"$0\" "$@""
|
||
|
exit $?
|
||
|
fi
|
||
|
|
||
|
|
||
|
export FREEPORT="$(findFreePort)"
|
||
|
API="http://localhost:$FREEPORT"
|
||
|
|
||
|
# Subcommand is test and checks succeeded
|
||
|
subcommand "$SUBCOMMAND"
|
||
|
STATUS=$?
|
||
|
if [ $STATUS -eq 0 ]; then
|
||
|
if [[ "$SUBCOMMAND" = "test" ]]; then
|
||
|
cat ../default.toml | envsubst > "$QBTNOX_DIR"/config.toml
|
||
|
export CFGFILE="$QBTNOX_DIR"/config.toml
|
||
|
if ../qbittorrent-nox.sh start "$QBTNOX_DIR" "$FREEPORT"; then
|
||
|
runTests "$API"
|
||
|
STATUS=$?
|
||
|
../qbittorrent-nox.sh stop "$QBTNOX_DIR"
|
||
|
else
|
||
|
echo "qBittorrent did not start"
|
||
|
STATUS=1
|
||
|
fi
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
if [[ "${TESTRUNNER:-plz}" = "plz" ]]; then
|
||
|
rm -R "$QBTNOX_DIR"
|
||
|
fi
|
||
|
cd "$ORIGDIR"
|
||
|
exit $STATUS
|