specs/forgehook/test.sh

80 lines
2.3 KiB
Bash
Raw Normal View History

2020-09-29 10:37:55 +00:00
#! /bin/bash
SCRIPTDIR="$(dirname "$0")"
2022-02-20 23:40:25 +00:00
ORIGDIR="$(pwd)"
cd "$SCRIPTDIR"
source tests/helper.bash
export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh"
# TODO: FORGEHOOKNOTIFY is currently unused
export FORGEHOOKNOTIFY=/bin/true
2020-09-29 10:37:55 +00:00
2022-02-20 16:33:36 +00:00
2020-09-29 10:37:55 +00:00
if [ -z "$1" ]; then
2022-02-20 23:40:25 +00:00
output="$(findBin "$ORIGDIR"/bin/server ../bin/server)"
2022-02-20 16:33:36 +00:00
if [ $? -eq 0 ]; then
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
2022-02-20 23:40:25 +00:00
export FIND_SERVER="$output"
2022-02-20 16:33:36 +00:00
else
# Some warnings, print but use result from last line
echo "$output" | head -n -1
2022-02-20 23:40:25 +00:00
export FIND_SERVER="$(echo "$output" | tail -n 1)"
2022-02-20 16:33:36 +00:00
fi
else
echo "ERROR: Could not find webhook endpoint server starting script. Output:"
echo "$output"
exit 1
fi
2022-02-20 23:40:25 +00:00
# server script needs to be executed to get absolute path to the program
export FORGEHOOKENDPOINT="$("$FIND_SERVER")"
2022-02-20 16:33:36 +00:00
else
2022-02-20 23:40:25 +00:00
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
2022-02-20 16:33:36 +00:00
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)
2022-02-20 16:33:36 +00:00
output="$(findBin \
whck/bin/cli \
../whck/bin/cli
2022-02-20 16:33:36 +00:00
)"
if [ $? -eq 0 ]; then
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
export FIND_WHCK="$output"
2022-02-20 16:33:36 +00:00
else
# Some warnings, print but use result from last line
echo "$output" | head -n -1
export FIND_WHCK="$(echo "$output" | tail -n 1)"
2022-02-20 16:33:36 +00:00
fi
2020-09-29 10:37:55 +00:00
else
2022-02-20 16:33:36 +00:00
echo "ERROR: Could not find webhook check program (whck). Output:"
echo "$output"
2020-09-29 10:37:55 +00:00
exit 1
fi
# cli script needs to be executed to get absolute path to the program
export WHCK="$("$FIND_WHCK")"
2020-09-29 10:37:55 +00:00
else
2022-02-20 23:40:25 +00:00
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
2020-09-29 10:37:55 +00:00
2022-02-20 23:40:25 +00:00
fi
2022-02-20 16:33:36 +00:00
bats tests/web/*.bats
2022-02-20 23:40:25 +00:00
status=$?
2020-09-29 10:37:55 +00:00
cd "$ORIGDIR"
2022-02-20 23:40:25 +00:00
exit $status