2019-08-05 23:33:55 +02:00
|
|
|
#!/bin/bash
|
2020-08-03 11:58:43 +02:00
|
|
|
# Script for running functional tests against the CLI
|
2019-08-05 23:33:55 +02:00
|
|
|
|
|
|
|
# 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/>
|
|
|
|
|
2020-08-03 11:58:43 +02:00
|
|
|
# ================================== CONFIG ================================== #
|
|
|
|
|
|
|
|
cd "${BASH_SOURCE%/*}/" || exit 1
|
|
|
|
|
|
|
|
if [[ ${1} ]]; then
|
|
|
|
version="${1}"
|
|
|
|
else
|
|
|
|
version="3.2"
|
2019-08-05 23:33:55 +02:00
|
|
|
fi
|
|
|
|
|
2020-08-03 11:58:43 +02:00
|
|
|
refine="openrefine-${version}/refine"
|
|
|
|
|
|
|
|
# =============================== 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
|
2019-08-06 22:01:20 +02:00
|
|
|
fi
|
2020-08-03 11:58:43 +02:00
|
|
|
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
|
2019-08-06 22:01:20 +02:00
|
|
|
fi
|
2020-08-03 11:58:43 +02:00
|
|
|
# download OpenRefine
|
|
|
|
if [[ -z "$(readlink -e "${refine}")" ]]; then
|
|
|
|
echo "Download OpenRefine..."
|
|
|
|
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 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
|
2019-08-06 22:01:20 +02:00
|
|
|
fi
|
|
|
|
|
2020-08-03 11:58:43 +02:00
|
|
|
# ================================== SETUP =================================== #
|
|
|
|
|
|
|
|
dir="$(readlink -f "tests/tmp")"
|
|
|
|
mkdir -p ${dir}
|
|
|
|
rm -f tests.log
|
|
|
|
|
|
|
|
echo "start OpenRefine server..."
|
|
|
|
${refine} -v warn -p 3334 -d "${dir}" &>> tests.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/*.sh; do
|
|
|
|
tests+=("${t}")
|
|
|
|
echo "========================= ${t} =========================" &>> tests.log
|
|
|
|
${t} ${version} >> tests.log
|
|
|
|
results+=(${?})
|
2019-08-05 23:33:55 +02:00
|
|
|
done
|
2020-08-03 11:58:43 +02:00
|
|
|
echo
|
|
|
|
|
|
|
|
# ================================= SUMMARY ================================== #
|
|
|
|
|
|
|
|
for i in "${!tests[@]}"; do
|
|
|
|
printf "%s\t%s\n" "code" "test"
|
|
|
|
printf "%s\t%s\n" "----" "----------------"
|
|
|
|
printf "%s\t%s\n" "${results[$i]}" "${tests[$i]}"
|
2019-08-05 23:33:55 +02:00
|
|
|
done
|
2020-08-03 11:58:43 +02:00
|
|
|
echo
|
|
|
|
if [[ " ${results[@]} " =~ [1-9] ]]; then
|
|
|
|
echo "failed tests! check tests.log for debugging"; echo
|
|
|
|
else
|
|
|
|
echo "all tests passed!"; echo
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ================================= TEARDOWN ================================= #
|
|
|
|
|
|
|
|
echo "cleanup..."
|
|
|
|
{ kill -9 "${pid_server}" && wait "${pid_server}"; } 2>/dev/null
|
|
|
|
rm -rf ${dir}
|