specs/forgehook/test.sh

80 lines
2.3 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 build script from whck/ in current folder (called from endpoints.php repo)
# Or try build script from ../whck folder (called from this submodule)
output="$(findBin \
whck/bin/cli \
../whck/bin/cli
)"
if [ $? -eq 0 ]; then
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
export FIND_WHCK="$output"
else
# Some warnings, print but use result from last line
echo "$output" | head -n -1
export FIND_WHCK="$(echo "$output" | tail -n 1)"
fi
else
echo "ERROR: Could not find webhook check program (whck). Output:"
echo "$output"
exit 1
fi
# cli script needs to be executed to get absolute path to the program
export WHCK="$("$FIND_WHCK")"
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