-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_command.sh
76 lines (67 loc) · 2.39 KB
/
test_command.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# shellcheck shell=bash disable=SC2154
# 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
# 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
# create tmp directory
OPENREFINE_TMPDIR="$(mktemp -d)"
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
# 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" &
OPENREFINE_PID="$!"
# update trap to kill OpenRefine on error or exit
trap '{ rm -rf "$OPENREFINE_TMPDIR"; rm -rf /tmp/jetty-127_0_0_1-3333*; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15
# wait until OpenRefine is running (timeout 20s)
for i in {1..20}; do
sleep 1
if curl -fs "${OPENREFINE_URL}/command/core/get-version" &>/dev/null; then
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
break
fi
if [[ $i == 20 ]]; then
error "starting OpenRefine server failed!"
fi
done
# execute tests in subshell
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
cd "tests"
files=(*.sh)
results=()
for i in "${!files[@]}"; do
set +e # do not exit on failed tests
bash -e <(
echo "shopt -s expand_aliases"
echo "alias orcli=${scriptpath}/orcli"
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
# print overall result
if [[ "${results[*]}" =~ [1-9] ]]; then
error "failed tests!"
else
log "all tests passed!"
fi