Merge pull request #85 from opencultureconsulting/felixlohmeier/functional-tests-7
first draft functional tests
This commit is contained in:
commit
d1486c5929
|
@ -137,3 +137,9 @@ orcli uses [bashly](https://github.com/DannyBen/bashly/) for generating the one-
|
||||||
```sh
|
```sh
|
||||||
bashly generate --upgrade
|
bashly generate --upgrade
|
||||||
```
|
```
|
||||||
|
|
||||||
|
4. Run tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./orcli test
|
||||||
|
```
|
|
@ -116,6 +116,9 @@ commands:
|
||||||
- orcli info "duplicates"
|
- orcli info "duplicates"
|
||||||
- orcli info 1234567890123
|
- orcli info 1234567890123
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
help: run functional tests on tmp OpenRefine workspace
|
||||||
|
|
||||||
- name: transform
|
- name: transform
|
||||||
help: apply undo/redo JSON file(s) to an OpenRefine project
|
help: apply undo/redo JSON file(s) to an OpenRefine project
|
||||||
args:
|
args:
|
||||||
|
|
|
@ -66,12 +66,16 @@ send_completions() {
|
||||||
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )'
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )'
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
|
echo $' \'test\'*)'
|
||||||
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help -h")" -- "$cur" )'
|
||||||
|
echo $' ;;'
|
||||||
|
echo $''
|
||||||
echo $' \'run\'*)'
|
echo $' \'run\'*)'
|
||||||
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port --quiet -h -q")" -- "$cur" )'
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --interactive --memory --port --quiet -h -q")" -- "$cur" )'
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' *)'
|
echo $' *)'
|
||||||
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --version -h -v completions export import info list run transform")" -- "$cur" )'
|
echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_orcli_completions_filter "--help --version -h -v completions export import info list run test transform")" -- "$cur" )'
|
||||||
echo $' ;;'
|
echo $' ;;'
|
||||||
echo $''
|
echo $''
|
||||||
echo $' esac'
|
echo $' esac'
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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"; kill -9 "$OPENREFINE_PID"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# 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 <(
|
||||||
|
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
|
||||||
|
|
||||||
|
# print overall result
|
||||||
|
if [[ "${results[*]}" =~ [1-9] ]]; then
|
||||||
|
error "failed tests!"
|
||||||
|
else
|
||||||
|
log "all tests passed!"
|
||||||
|
fi
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="completions"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cat << "DATA" > "${tmpdir}/${t}.assert"
|
||||||
|
# orcli completion -*- shell-script -*-
|
||||||
|
DATA
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli completions | head -n1 > "${t}.output"
|
||||||
|
|
||||||
|
# test
|
||||||
|
diff -u "${t}.assert" "${t}.output"
|
|
@ -0,0 +1,7 @@
|
||||||
|
email count name state gender purchase
|
||||||
|
arthur.duff@example4.com 2 Arthur Duff OR M Dining table
|
||||||
|
ben.morisson@example6.org 1 Ben Morisson FL M Amplifier
|
||||||
|
ben.tyler@example3.org 1 Ben Tyler NV M Flashlight
|
||||||
|
danny.baron@example1.com 3 Danny Baron CA M TV
|
||||||
|
jean.griffith@example5.org 1 Jean Griffith WA F Power drill
|
||||||
|
melanie.white@example2.edu 2 Melanie White NC F iPhone
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
email,name,state,gender,purchase
|
||||||
|
danny.baron@example1.com,Danny Baron,CA,M,TV
|
||||||
|
melanie.white@example2.edu,Melanie White,NC,F,iPhone
|
||||||
|
danny.baron@example1.com,D. Baron,CA,M,Winter jacket
|
||||||
|
ben.tyler@example3.org,Ben Tyler,NV,M,Flashlight
|
||||||
|
arthur.duff@example4.com,Arthur Duff,OR,M,Dining table
|
||||||
|
danny.baron@example1.com,Daniel Baron,CA,M,Bike
|
||||||
|
jean.griffith@example5.org,Jean Griffith,WA,F,Power drill
|
||||||
|
melanie.white@example2.edu,Melanie White,NC,F,iPad
|
||||||
|
ben.morisson@example6.org,Ben Morisson,FL,M,Amplifier
|
||||||
|
arthur.duff@example4.com,Arthur Duff,OR,M,Night table
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
email name state gender purchase
|
||||||
|
danny.baron@example1.com Danny Baron CA M TV
|
||||||
|
melanie.white@example2.edu Melanie White NC F iPhone
|
||||||
|
danny.baron@example1.com D. Baron CA M Winter jacket
|
||||||
|
ben.tyler@example3.org Ben Tyler NV M Flashlight
|
||||||
|
arthur.duff@example4.com Arthur Duff OR M Dining table
|
||||||
|
danny.baron@example1.com Daniel Baron CA M Bike
|
||||||
|
jean.griffith@example5.org Jean Griffith WA F Power drill
|
||||||
|
melanie.white@example2.edu Melanie White NC F iPad
|
||||||
|
ben.morisson@example6.org Ben Morisson FL M Amplifier
|
||||||
|
arthur.duff@example4.com Arthur Duff OR M Night table
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
a,b,c
|
||||||
|
1,2,3
|
||||||
|
0,0,0
|
||||||
|
$,\,'
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
a b c
|
||||||
|
1 2 3
|
||||||
|
0 0 0
|
||||||
|
$ \ '
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="export-tsv"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# input
|
||||||
|
cp data/example.csv "${tmpdir}/${t}.csv"
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cp data/example.tsv "${tmpdir}/${t}.assert"
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli import csv "${t}.csv"
|
||||||
|
orcli export tsv "${t} csv" --output "${t}.output"
|
||||||
|
|
||||||
|
# test
|
||||||
|
diff -u "${t}.assert" "${t}.output"
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="help"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cat << "DATA" > "${tmpdir}/${t}.assert"
|
||||||
|
orcli - OpenRefine command-line interface written in Bash
|
||||||
|
DATA
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli --help | head -n1 > "${t}.output"
|
||||||
|
|
||||||
|
# test
|
||||||
|
diff -u "${t}.assert" "${t}.output"
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="import-csv"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# input
|
||||||
|
cp data/example.csv "${tmpdir}/${t}.csv"
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cp data/example.tsv "${tmpdir}/${t}.assert"
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli import csv "${t}.csv"
|
||||||
|
orcli export tsv "${t} csv" > "${t}.output"
|
||||||
|
|
||||||
|
# test
|
||||||
|
diff -u "${t}.assert" "${t}.output"
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="info"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# input
|
||||||
|
cp data/example.csv "${tmpdir}/${t}.csv"
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli import csv "${t}.csv"
|
||||||
|
orcli info "${t} csv"
|
||||||
|
|
||||||
|
# test
|
||||||
|
# grep "${t}" "${t}.output"
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="list"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# input
|
||||||
|
cp data/example.csv "${tmpdir}/${t}.csv"
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli import csv "${t}.csv"
|
||||||
|
orcli list > "${t}.output"
|
||||||
|
|
||||||
|
# test
|
||||||
|
grep "${t}" "${t}.output"
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="run"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cp data/duplicates-transformed.tsv "${tmpdir}/${t}.assert"
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli run --memory "2000M" --port "3334" << EOF
|
||||||
|
orcli import csv "https://git.io/fj5hF" --projectName "duplicates"
|
||||||
|
orcli transform "duplicates" "https://git.io/fj5ju"
|
||||||
|
orcli export tsv "duplicates" --output "${t}.output"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# test
|
||||||
|
diff -u "${t}.assert" "${t}.output"
|
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
t="transform"
|
||||||
|
|
||||||
|
# create tmp directory
|
||||||
|
tmpdir="$(mktemp -d)"
|
||||||
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cp data/duplicates-transformed.tsv "${tmpdir}/${t}.assert"
|
||||||
|
|
||||||
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
|
orcli import csv "https://git.io/fj5hF" --projectName "duplicates"
|
||||||
|
orcli transform "duplicates" "https://git.io/fj5ju"
|
||||||
|
orcli export tsv "duplicates" --output "${t}.output"
|
||||||
|
|
||||||
|
# test
|
||||||
|
diff -u "${t}.assert" "${t}.output"
|
Loading…
Reference in New Issue