add (functional) test framework
This commit is contained in:
parent
b126a63d68
commit
69209f04df
|
@ -4,4 +4,5 @@ dist
|
||||||
.*
|
.*
|
||||||
openrefine_client.egg-info
|
openrefine_client.egg-info
|
||||||
refine.spec
|
refine.spec
|
||||||
README.html
|
openrefine-3.*
|
||||||
|
tests.log
|
||||||
|
|
185
tests.sh
185
tests.sh
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Script for running tests with different OpenRefine and Java versions based on Docker images.
|
# Script for running functional tests against the CLI
|
||||||
|
|
||||||
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
|
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
|
||||||
|
|
||||||
|
@ -16,115 +16,92 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
|
||||||
# defaults:
|
# ================================== CONFIG ================================== #
|
||||||
all=(3.2-java12 3.2-java11 3.2-java10 3.2-java9 3.2 3.1-java9 3.1 3.0-java9 3.0 2.8-java9 2.8 2.8-java7 2.7 2.7-java7 2.5-java7 2.5-java6 2.1-java6 2.0-java6)
|
|
||||||
main=(3.2 3.1 3.0 2.8 2.7 2.5-java6 2.1-java6 2.0-java6)
|
|
||||||
interactively=false
|
|
||||||
port="3333"
|
|
||||||
|
|
||||||
# help screen
|
cd "${BASH_SOURCE%/*}/" || exit 1
|
||||||
function usage () {
|
|
||||||
cat <<EOF
|
|
||||||
Usage: ./tests.sh [-t TAG] [-i] [-p] [-a] [-h]
|
|
||||||
|
|
||||||
Script for running tests with different OpenRefine and Java versions.
|
if [[ ${1} ]]; then
|
||||||
It uses docker images from https://hub.docker.com/r/felixlohmeier/openrefine.
|
version="${1}"
|
||||||
|
|
||||||
Examples:
|
|
||||||
./tests.sh -a # run tests on all OpenRefine versions (from 2.0 up to 3.2)
|
|
||||||
./tests.sh -t 3.2 # run tests on tag 3.2
|
|
||||||
./tests.sh -t 3.2 -i # run tests on tag 3.2 interactively (pause before and after tests)
|
|
||||||
./tests.sh -t 3.2 -t 2.7 # run tests on tags 3.2 and 2.7
|
|
||||||
|
|
||||||
Advanced:
|
|
||||||
./tests.sh -j # run tests on all OpenRefine versions and each with all supported Java versions (requires a lot of docker images to be downloaded!)
|
|
||||||
./tests.sh -t 3.1 -i -p 3334 # run tests on tag 3.1 interactively on port 3334
|
|
||||||
|
|
||||||
Running tests interactively (-i) allows you to examine OpenRefine GUI at http://localhost:3333.
|
|
||||||
Execute the script concurrently in another terminal on another port (-p 3334) to compare changes in the OpenRefine GUI at http://localhost:3333 and http://localhost:3334.
|
|
||||||
|
|
||||||
Available tags (java 8 if java not mentioned in tag):
|
|
||||||
EOF
|
|
||||||
for t in ${all[*]} ; do
|
|
||||||
echo "$t"
|
|
||||||
done
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# check input
|
|
||||||
NUMARGS=$#
|
|
||||||
if [ "$NUMARGS" -eq 0 ]; then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check system requirements
|
|
||||||
DOCKER="$(command -v docker 2> /dev/null)"
|
|
||||||
if [ -z "$DOCKER" ] ; then
|
|
||||||
echo 1>&2 "This action requires you to have 'docker' installed and present in your PATH. You can download it for free at http://www.docker.com/"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
DOCKERINFO="$(docker info 2>/dev/null | grep 'Server Version')"
|
|
||||||
if [ -z "$DOCKERINFO" ]
|
|
||||||
then
|
|
||||||
echo "command 'docker info' failed, trying again with sudo..."
|
|
||||||
DOCKERINFO="$(sudo docker info 2>/dev/null | grep 'Server Version')"
|
|
||||||
echo "OK"
|
|
||||||
docker=(sudo docker)
|
|
||||||
if [ -z "$DOCKERINFO" ] ; then
|
|
||||||
echo 1>&2 "This action requires you to start the docker daemon. Try 'sudo systemctl start docker' or 'sudo start docker'. If the docker daemon is already running then maybe some security privileges are missing to run docker commands.'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
docker=(docker)
|
version="3.2"
|
||||||
fi
|
|
||||||
CURLINFO="$(command -v curl 2>/dev/null)"
|
|
||||||
if [ -z "$CURLINFO" ] ; then
|
|
||||||
echo 1>&2 "This action requires you to have 'curl' installed and present in your PATH."
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# get user input
|
refine="openrefine-${version}/refine"
|
||||||
options="t:p:iajh"
|
|
||||||
while getopts $options opt; do
|
# =============================== REQUIREMENTS =============================== #
|
||||||
case $opt in
|
|
||||||
t ) tags+=("${OPTARG}");;
|
# check existence of java and cURL
|
||||||
p ) port="${OPTARG}";export OPENREFINE_PORT="$port";;
|
if [[ -z "$(command -v java 2> /dev/null)" ]] ; then
|
||||||
i ) interactively=true;;
|
echo 1>&2 "ERROR: OpenRefine requires JAVA runtime environment (jre)" \
|
||||||
a ) tags=("${main[*]}");;
|
"https://openjdk.java.net/install/"
|
||||||
j ) tags=("${all[*]}");;
|
exit 1
|
||||||
h ) usage ;;
|
fi
|
||||||
\? ) echo 1>&2 "Unknown option: -$OPTARG"; usage; exit 1;;
|
if [[ -z "$(command -v curl 2> /dev/null)" ]] ; then
|
||||||
: ) echo 1>&2 "Missing option argument for -$OPTARG"; usage; exit 1;;
|
echo 1>&2 "ERROR: This shell script requires cURL" \
|
||||||
* ) echo 1>&2 "Unimplemented option: -$OPTARG"; usage; exit 1;;
|
"https://curl.haxx.se/download.html"
|
||||||
esac
|
exit 1
|
||||||
|
fi
|
||||||
|
# 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
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ================================== 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+=(${?})
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
echo
|
||||||
|
|
||||||
# print config
|
# ================================= SUMMARY ================================== #
|
||||||
echo "Tags: ${tags[*]}"
|
|
||||||
echo "Port: $port"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# safe cleanup handler
|
for i in "${!tests[@]}"; do
|
||||||
cleanup()
|
printf "%s\t%s\n" "code" "test"
|
||||||
{
|
printf "%s\t%s\n" "----" "----------------"
|
||||||
echo "cleanup..."
|
printf "%s\t%s\n" "${results[$i]}" "${tests[$i]}"
|
||||||
${docker[*]} stop "$t"
|
|
||||||
}
|
|
||||||
trap "cleanup;exit" SIGHUP SIGINT SIGQUIT SIGTERM
|
|
||||||
|
|
||||||
# run setup.py tests for each docker tag
|
|
||||||
for t in ${tags[*]} ; do
|
|
||||||
echo "=== Tests for $t ==="
|
|
||||||
echo ""
|
|
||||||
echo "Begin: $(date)"
|
|
||||||
${docker[*]} run -d -p "$port":3333 --rm --name "$t" felixlohmeier/openrefine:"$t"
|
|
||||||
until curl --silent -N http://localhost:"$port" | cat | grep -q -o "Refine" ; do sleep 1; done
|
|
||||||
echo "Refine running at http://localhost:${port}"
|
|
||||||
if [ $interactively = true ]; then read -r -p "Press [Enter] key to start tests..."; fi
|
|
||||||
python2 setup.py test
|
|
||||||
if [ $interactively = true ]; then read -r -p "Press [Enter] key to stop OpenRefine..."; fi
|
|
||||||
${docker[*]} stop "$t"
|
|
||||||
echo "End: $(date)"
|
|
||||||
echo ""
|
|
||||||
done
|
done
|
||||||
|
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}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# =============================== ENVIRONMENT ================================ #
|
||||||
|
|
||||||
|
t="create-csv"
|
||||||
|
|
||||||
|
cd "${BASH_SOURCE%/*}/" || exit 1
|
||||||
|
client="python3 ../refine.py -H localhost -P 3334"
|
||||||
|
mkdir -p "tmp/${t}"
|
||||||
|
|
||||||
|
# =================================== DATA =================================== #
|
||||||
|
|
||||||
|
cat << "DATA" > "tmp/${t}/${t}.csv"
|
||||||
|
a,b,c
|
||||||
|
1,2,3
|
||||||
|
0,0,0
|
||||||
|
$,\,'
|
||||||
|
DATA
|
||||||
|
|
||||||
|
# ================================= ASSERTION ================================ #
|
||||||
|
|
||||||
|
cat << "DATA" > "tmp/${t}/${t}.assert"
|
||||||
|
a b c
|
||||||
|
1 2 3
|
||||||
|
0 0 0
|
||||||
|
$ \ '
|
||||||
|
DATA
|
||||||
|
|
||||||
|
# ================================== ACTION ================================== #
|
||||||
|
|
||||||
|
${client} --create "tmp/${t}/${t}.csv"
|
||||||
|
${client} --export "${t}" --output "tmp/${t}/${t}.output"
|
||||||
|
|
||||||
|
# =================================== TEST =================================== #
|
||||||
|
|
||||||
|
diff -u "tmp/${t}/${t}.assert" "tmp/${t}/${t}.output"
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# =============================== ENVIRONMENT ================================ #
|
||||||
|
|
||||||
|
t="test"
|
||||||
|
|
||||||
|
if [[ ${1} ]]; then
|
||||||
|
version="${1##*.}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "${BASH_SOURCE%/*}/" || exit 1
|
||||||
|
client="python3 ../refine.py -H localhost -P 3334"
|
||||||
|
mkdir -p "tmp/${t}"
|
||||||
|
|
||||||
|
# =================================== DATA =================================== #
|
||||||
|
|
||||||
|
cat << "DATA" > "tmp/${t}/${t}.csv"
|
||||||
|
a,b,c
|
||||||
|
1,2,3
|
||||||
|
0,0,0
|
||||||
|
$,\,'
|
||||||
|
DATA
|
||||||
|
|
||||||
|
cat << "DATA" > "tmp/${t}/${t}.transform"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"op": "core/column-addition",
|
||||||
|
"engineConfig": {
|
||||||
|
"mode": "row-based"
|
||||||
|
},
|
||||||
|
"newColumnName": "apply",
|
||||||
|
"columnInsertIndex": 2,
|
||||||
|
"baseColumnName": "b",
|
||||||
|
"expression": "grel:value.replace('2','TEST')",
|
||||||
|
"onError": "set-to-blank"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
DATA
|
||||||
|
|
||||||
|
# ================================= ASSERTION ================================ #
|
||||||
|
|
||||||
|
# if [[ "$version" >= 2 ]]; then
|
||||||
|
cat << "DATA" > "tmp/${t}/${t}.assert"
|
||||||
|
a b apply c
|
||||||
|
1 2 TEST 3
|
||||||
|
0 0 0 0
|
||||||
|
$ \ \ '
|
||||||
|
DATA
|
||||||
|
# else
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# ================================== ACTION ================================== #
|
||||||
|
|
||||||
|
${client} --create "tmp/${t}/${t}.csv"
|
||||||
|
${client} --apply "tmp/${t}/${t}.transform" "${t}"
|
||||||
|
${client} --export "${t}" --output "tmp/${t}/${t}.output"
|
||||||
|
|
||||||
|
# =================================== TEST =================================== #
|
||||||
|
|
||||||
|
diff -u "tmp/${t}/${t}.assert" "tmp/${t}/${t}.output"
|
Loading…
Reference in New Issue