specs/test_web.sh

83 lines
2.4 KiB
Bash
Executable File

#! /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
if [ -z "$1" ]; then
output="$(findBin "$ORIGDIR"/bin/server ../bin/server)"
if [ $? -eq 0 ]; then
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
export FIND_SERVER="$output"
else
# Some warnings, print but use result from last line
echo "$output" | head -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
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 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 \
../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
export WHCK="$output"
else
# Some warnings, print but use result from last line
echo "$output" | head -n -1
export WHCK="$(echo "$output" | tail -n 1)"
fi
else
echo "ERROR: Could not find webhook check program (whck). Output:"
echo "$output"
exit 1
fi
else
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
bats tests/web/*.bats
status=$?
cd "$ORIGDIR"
exit $status