This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
forked from paulmakepeace/refine-client-py
-
Notifications
You must be signed in to change notification settings - Fork 19
/
tests-cli.sh
executable file
·123 lines (102 loc) · 3.79 KB
/
tests-cli.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Script for running functional tests against the CLI
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
# ================================== CONFIG ================================== #
cd "${BASH_SOURCE%/*}/" || exit 1
port=3334
if [[ ${1} ]]; then
version="${1}"
else
version="3.2"
fi
refine="openrefine-${version}/refine"
if [[ ${2} ]]; then
client="$(readlink -e "${2}")"
else
client="python2 $(readlink -e refine.py)"
fi
cmd="${client} -H localhost -P ${port}"
if [[ ${3} ]]; then
filename="${3%%.*}"
else
filename=""
fi
cmd="${client} -H localhost -P ${port}"
# =============================== REQUIREMENTS =============================== #
# check existence of java and cURL
if [[ -z "$(command -v java 2> /dev/null)" ]] ; then
echo 1>&2 "ERROR: OpenRefine requires JAVA runtime environment (jre)" \
"https://openjdk.java.net/install/"
exit 1
fi
if [[ -z "$(command -v curl 2> /dev/null)" ]] ; then
echo 1>&2 "ERROR: This shell script requires cURL" \
"https://curl.haxx.se/download.html"
exit 1
fi
# download OpenRefine
if [[ -z "$(readlink -e "${refine}")" ]]; then
echo "Download OpenRefine ${version}..."
mkdir -p "$(dirname "${refine}")"
curl -L --output openrefine.tar.gz \
"https://github.com/OpenRefine/OpenRefine/releases/download/${version}/openrefine-linux-${version}.tar.gz"
echo "Install OpenRefine ${version} in subdirectory $(dirname "${refine}")..."
tar -xzf openrefine.tar.gz -C "$(dirname "${refine}")" --strip 1 --totals
rm -f openrefine.tar.gz
# do not try to open OpenRefine in browser
sed -i '$ a JAVA_OPTIONS=-Drefine.headless=true' \
"$(dirname "${refine}")"/refine.ini
# set autosave period from 5 minutes to 25 hours
sed -i 's/#REFINE_AUTOSAVE_PERIOD=60/REFINE_AUTOSAVE_PERIOD=1500/' \
"$(dirname "${refine}")"/refine.ini
echo
fi
# ================================== SETUP =================================== #
dir="$(readlink -f "tests/tmp")"
mkdir -p "${dir}"
rm -f tests-cli.log
echo "start OpenRefine ${version}..."
${refine} -v warn -p ${port} -d "${dir}" &>> tests-cli.log &
pid_server=${!}
timeout 30s bash -c "until curl -s 'http://localhost:3334' \
| cat | grep -q -o 'OpenRefine' ; do sleep 1; done" \
|| error "starting OpenRefine server failed!"
echo
# ================================== TESTS =================================== #
echo "running tests, please wait..."
tests=()
results=()
for t in tests/*${filename}*.sh; do
tests+=("${t}")
echo "======================= ${t} =======================" &>> tests-cli.log
bash "${t}" "${cmd}" "${version}" &>> tests-cli.log
results+=(${?})
done
echo
# ================================= TEARDOWN ================================= #
echo "cleanup..."
{ kill -9 "${pid_server}" && wait "${pid_server}"; } 2>/dev/null
rm -rf "${dir}"
echo
# ================================= SUMMARY ================================== #
printf "%s\t%s\n" "code" "test"
printf "%s\t%s\n" "----" "----------------"
for i in "${!tests[@]}"; do
printf "%s\t%s\n" "${results[$i]}" "${tests[$i]}"
done
echo
if [[ " ${results[*]} " =~ [1-9] ]]; then
echo "failed tests! check tests-cli.log for debugging"; echo
else
echo "all tests passed!"; echo
fi