specs/forgecheck/test.sh

47 lines
1.2 KiB
Bash
Executable File

#! /bin/bash
# Test me with: ./test_cli.sh PATH/TO/PROGRAM
SCRIPTDIR="$(dirname "$0")"
ORIGDIR="$(pwd)"
cd "$SCRIPTDIR"
export FORGEHOOK="$(realpath ../shared/mock-forgehook.sh)"
source ../shared/helper.bash
if [ -z "$1" ]; then
output="$(findBin "$ORIGDIR"/bin/cli ../bin/cli ../../bin/cli ../../../bin/cli)"
if [ $? -eq 0 ]; then
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
FIND_WHCK="$output"
else
# Some warnings, print but use result from last line
echo "$output" | head -n -1
FIND_WHCK="$(echo "$output" | tail -n 1)"
fi
else
echo "ERROR: Could not find webhook validation program. 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 [ -f "$ORIGDIR"/"$1" ] && [ -x "$ORIGDIR"/"$1" ]; then
export WHCK="$(realpath "$ORIGDIR"/"$1")"
elif [ -f "$1" ] && [ -x "$1" ]; then
export WHCK="$(realpath "$1")"
else
echo "ERROR: Could not find provided validation program: "$1""
exit 2
fi
fi
bats tests/*.bats
status=$?
cd "$ORIGDIR"
exit $status