2022-12-01 23:43:52 +01:00
|
|
|
# shellcheck shell=bash disable=SC2154
|
2022-11-30 23:49:54 +01:00
|
|
|
|
|
|
|
# locate orcli and OpenRefine
|
|
|
|
scriptpath=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
|
|
|
if [[ -x "${scriptpath}/refine" ]]; then
|
|
|
|
openrefine="${scriptpath}/refine"
|
|
|
|
else
|
|
|
|
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
|
|
|
|
fi
|
|
|
|
|
2022-12-06 12:39:08 +01:00
|
|
|
# check if OpenRefine is already running
|
|
|
|
if curl -fs "${OPENREFINE_URL}" &>/dev/null; then
|
|
|
|
error "OpenRefine is already running on port 3333." "Please stop the other process."
|
|
|
|
fi
|
|
|
|
|
2022-11-30 23:49:54 +01:00
|
|
|
# create tmp directory
|
|
|
|
OPENREFINE_TMPDIR="$(mktemp -d)"
|
|
|
|
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
|
|
|
|
|
2022-12-04 00:39:53 +01:00
|
|
|
# download the test files if needed
|
|
|
|
if ! [[ -f "tests/help.sh" ]]; then
|
|
|
|
cd "$OPENREFINE_TMPDIR"
|
|
|
|
if ! curl -fs -L -o orcli.zip https://github.com/opencultureconsulting/orcli/archive/refs/heads/main.zip; then
|
|
|
|
error "downloading test files failed!" "Please download the tests dir manually from GitHub."
|
|
|
|
fi
|
|
|
|
unzip -q -j orcli.zip "*/tests/*.sh" -d "tests/"
|
|
|
|
unzip -q -j orcli.zip "*/tests/data/*" -d "tests/data/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# start OpenRefine with tmp workspace
|
|
|
|
$openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" &
|
2022-11-30 23:49:54 +01:00
|
|
|
OPENREFINE_PID="$!"
|
|
|
|
|
|
|
|
# update trap to kill OpenRefine on error or exit
|
2022-12-06 12:39:08 +01:00
|
|
|
trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-3333*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15
|
2022-11-30 23:49:54 +01:00
|
|
|
|
|
|
|
# wait until OpenRefine is running (timeout 20s)
|
|
|
|
if ! curl -fs --retry 20 --retry-connrefused --retry-delay 1 "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
|
|
|
|
error "starting OpenRefine server failed!"
|
|
|
|
else
|
|
|
|
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
|
|
|
|
fi
|
|
|
|
|
2022-12-04 00:39:53 +01:00
|
|
|
# execute tests in subshell
|
2022-11-30 23:49:54 +01:00
|
|
|
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
|
2022-12-04 00:39:53 +01:00
|
|
|
cd "tests"
|
|
|
|
files=(*.sh)
|
2022-11-30 23:49:54 +01:00
|
|
|
results=()
|
|
|
|
for i in "${!files[@]}"; do
|
2022-12-04 00:39:53 +01:00
|
|
|
set +e # do not exit on failed tests
|
2022-12-01 23:43:52 +01:00
|
|
|
bash -e <(
|
2022-11-30 23:49:54 +01:00
|
|
|
if ! command -v orcli &>/dev/null; then
|
|
|
|
echo "shopt -s expand_aliases"
|
|
|
|
echo "alias orcli=${scriptpath}/orcli"
|
|
|
|
fi
|
|
|
|
awk 1 "${files[$i]}"
|
|
|
|
) &>"$OPENREFINE_TMPDIR/test.log"
|
|
|
|
results+=(${?})
|
|
|
|
set -e
|
|
|
|
if [[ "${results[$i]}" =~ [1-9] ]]; then
|
|
|
|
cat "$OPENREFINE_TMPDIR/test.log"
|
|
|
|
log "FAILED ${files[$i]} with exit code ${results[$i]}!"
|
|
|
|
else
|
|
|
|
log "PASSED ${files[$i]}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-12-04 00:39:53 +01:00
|
|
|
# print overall result
|
2022-11-30 23:49:54 +01:00
|
|
|
if [[ "${results[*]}" =~ [1-9] ]]; then
|
|
|
|
error "failed tests!"
|
|
|
|
else
|
|
|
|
log "all tests passed!"
|
|
|
|
fi
|