diff --git a/test_tests_web.sh b/test_tests_web.sh new file mode 100755 index 0000000..b676e86 --- /dev/null +++ b/test_tests_web.sh @@ -0,0 +1,45 @@ +#! /usr/bin/env bash + +# If you give first argument it will be a path to already cloned endpoint + +# TODO: save exit codes of various tests so we can know how many failed +function testVariousScenarios() { + echo "Running various tests from "$(pwd)"" + ./bin/test.sh || echo "ERROR running from repo" + cd spec + ./test_web.sh || echo "ERROR test_web.sh failed with implicit ../bin/server" + ./test_web.sh "$(../bin/server)" || echo "ERROR test_cli with explicit result from ../bin/server" + ../bin/test.sh || echo "ERROR bin/test.sh failed called from spec submodule" + cd tests + ../../bin/test.sh || echo "ERROR bin/test.sh failed from spec/tests folder" + ../test_web.sh || echo "ERROR test_web.sh failed from spec/tests folder with implicit ../../bin/server" + ../test_web.sh "$(../../bin/server)" || echo "ERROR test_web.sh failed from spec/tests folder with explicit result from ../../bin/server" +} + +ORIGDIR="$(pwd)" +if [ -z "$1" ]; then + # When no explicit dir, try ./ first, otherwise ../, otherwise make a temporary dir + if [ -x bin/server ]; then + testVariousScenarios + elif [ -x ../bin/server ]; then + cd .. + testVariousScenarios + else + TMPDIR="$(mktemp -d)" + cd "$TMPDIR" + git clone --recursive https://tildegit.org/forge/endpoints.php + cd endpoints.php + testVariousScenarios + cd "$ORIGDIR" + rm -rf "$TMPDIR" + fi +else + if [ ! -d "$1" ]; then + echo "Wrong repo: "$1"" + exit 1 + fi + cd "$1" + testVariousScenarios +fi + +cd "$ORIGDIR" diff --git a/test_web.sh b/test_web.sh index 3c29a08..af5a619 100755 --- a/test_web.sh +++ b/test_web.sh @@ -1,39 +1,54 @@ #! /bin/bash SCRIPTDIR="$(dirname "$0")" +ORIGDIR="$(pwd)" +cd "$SCRIPTDIR" + +source tests/helper.bash +export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh" +# TODO: FORGEHOOKNOTIFY is currently unused +export FORGEHOOKNOTIFY=/bin/true -source "$SCRIPTDIR"/tests/helper.bash if [ -z "$1" ]; then - output="$(findBin "$SCRIPTDIR"/server "$SCRIPTDIR"/../server)" + output="$(findBin "$ORIGDIR"/bin/server ../bin/server)" if [ $? -eq 0 ]; then if [[ "$(echo "$output" | wc -l)" == "1" ]]; then - export FORGEHOOKENDPOINT="$output" + export FIND_SERVER="$output" else # Some warnings, print but use result from last line echo "$output" | head -n -1 - export FORGEHOOKENDPOINT="$(echo "$output" | tail -n 1)" + export FIND_SERVER="$(echo "$output" | tail -n 1)" fi else echo "ERROR: Could not find webhook endpoint server starting script. Output:" echo "$output" exit 1 fi + # server script needs to be executed to get absolute path to the program + export FORGEHOOKENDPOINT="$("$FIND_SERVER")" else - export FORGEHOOKENDPOINT="$1" + if [ -x "$ORIGDIR"/"$1" ]; then + export FORGEHOOKENDPOINT="$(realpath "$ORIGDIR"/"$1")" + elif [ -x "$1" ]; then + export FORGEHOOKENDPOINT="$(realpath "$1")" + else + echo "ERROR: Could not find provided endpoint server: "$1"" + exit 2 + fi fi if [ -z "$2" ]; then - # First try symlink from script dir + # First try symlink from parent repo's bin/whck # Second try compiled version from parent repo (endpoint implementation) in whck submodule # Third try compiled version from whck folder in grandparent folder (eg. when called from # forge/endpoints.php/spec/test_web.sh to find forge/whck/target/*/whck) output="$(findBin \ - "$SCRIPTDIR"/whck \ - "$SCRIPTDIR"/../whck/target/release/whck \ - "$SCRIPTDIR"/../whck/target/debug/whck \ - "$SCRIPTDIR"/../../whck/target/release/whck \ - "$SCRIPTDIR"/../../whck/target/debug/whck \ + ../bin/whck \ + ../whck/target/release/whck \ + ../whck/target/debug/whck \ + ../../whck/target/release/whck \ + ../../whck/target/debug/whck \ )" if [ $? -eq 0 ]; then if [[ "$(echo "$output" | wc -l)" == "1" ]]; then @@ -49,15 +64,19 @@ if [ -z "$2" ]; then exit 1 fi else - export WHCK="$2" + if [ -x "$ORIGDIR"/"$2" ]; then + export WHCK="$(realpath "$ORIGDIR"/"$2")" + elif [ -x "$2" ]; then + export WHCK="$(realpath "$2")" + else + echo "ERROR: Could not find provided validation program: "$2"" + exit 2 + fi + fi -ORIGDIR="$(pwd)" -cd "$SCRIPTDIR" - -export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh" -export FORGEHOOKNOTIFY=/bin/true - bats tests/web/*.bats +status=$? cd "$ORIGDIR" +exit $status