additional tests

This commit is contained in:
felixlohmeier 2022-12-03 23:39:53 +00:00
parent 56c9bbe21e
commit 40de708115
13 changed files with 197 additions and 38 deletions

35
orcli
View File

@ -1051,24 +1051,27 @@ orcli_test_command() {
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
fi
# check existence of files
if ! [[ -f "tests/help.sh" ]]; then
error "Cannot open test files!"
fi
cd "tests"
files=(*.sh)
# create tmp directory
OPENREFINE_TMPDIR="$(mktemp -d)"
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
# check if OpenRefine is already running
if curl -fs "${OPENREFINE_URL}" &>/dev/null; then
error "OpenRefine is already running."
# 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 and autosave period 25 hours
REFINE_AUTOSAVE_PERIOD=1440 $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" &
# 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
@ -1081,11 +1084,13 @@ orcli_test_command() {
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
fi
# execute script(s) in subshell
# execute tests in subshell
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
cd "tests"
files=(*.sh)
results=()
for i in "${!files[@]}"; do
set +e
set +e # do not exit on failed tests
bash -e <(
if ! command -v orcli &>/dev/null; then
echo "shopt -s expand_aliases"
@ -1103,7 +1108,7 @@ orcli_test_command() {
fi
done
# summary
# print overall result
if [[ "${results[*]}" =~ [1-9] ]]; then
error "failed tests!"
else

View File

@ -8,24 +8,27 @@ else
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
fi
# check existence of files
if ! [[ -f "tests/help.sh" ]]; then
error "Cannot open test files!"
fi
cd "tests"
files=(*.sh)
# create tmp directory
OPENREFINE_TMPDIR="$(mktemp -d)"
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
# check if OpenRefine is already running
if curl -fs "${OPENREFINE_URL}" &>/dev/null; then
error "OpenRefine is already running."
# 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 and autosave period 25 hours
REFINE_AUTOSAVE_PERIOD=1440 $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" &
# 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
@ -38,11 +41,13 @@ else
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
fi
# execute script(s) in subshell
# execute tests in subshell
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
cd "tests"
files=(*.sh)
results=()
for i in "${!files[@]}"; do
set +e
set +e # do not exit on failed tests
bash -e <(
if ! command -v orcli &>/dev/null; then
echo "shopt -s expand_aliases"
@ -60,7 +65,7 @@ for i in "${!files[@]}"; do
fi
done
# summary
# print overall result
if [[ "${results[*]}" =~ [1-9] ]]; then
error "failed tests!"
else

19
tests/completions.sh Normal file
View File

@ -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"

View File

@ -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
1 email count name state gender purchase
2 arthur.duff@example4.com 2 Arthur Duff OR M Dining table
3 ben.morisson@example6.org 1 Ben Morisson FL M Amplifier
4 ben.tyler@example3.org 1 Ben Tyler NV M Flashlight
5 danny.baron@example1.com 3 Danny Baron CA M TV
6 jean.griffith@example5.org 1 Jean Griffith WA F Power drill
7 melanie.white@example2.edu 2 Melanie White NC F iPhone

11
tests/data/duplicates.csv Normal file
View File

@ -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
1 email name state gender purchase
2 danny.baron@example1.com Danny Baron CA M TV
3 melanie.white@example2.edu Melanie White NC F iPhone
4 danny.baron@example1.com D. Baron CA M Winter jacket
5 ben.tyler@example3.org Ben Tyler NV M Flashlight
6 arthur.duff@example4.com Arthur Duff OR M Dining table
7 danny.baron@example1.com Daniel Baron CA M Bike
8 jean.griffith@example5.org Jean Griffith WA F Power drill
9 melanie.white@example2.edu Melanie White NC F iPad
10 ben.morisson@example6.org Ben Morisson FL M Amplifier
11 arthur.duff@example4.com Arthur Duff OR M Night table

11
tests/data/duplicates.tsv Normal file
View File

@ -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
1 email name state gender purchase
2 danny.baron@example1.com Danny Baron CA M TV
3 melanie.white@example2.edu Melanie White NC F iPhone
4 danny.baron@example1.com D. Baron CA M Winter jacket
5 ben.tyler@example3.org Ben Tyler NV M Flashlight
6 arthur.duff@example4.com Arthur Duff OR M Dining table
7 danny.baron@example1.com Daniel Baron CA M Bike
8 jean.griffith@example5.org Jean Griffith WA F Power drill
9 melanie.white@example2.edu Melanie White NC F iPad
10 ben.morisson@example6.org Ben Morisson FL M Amplifier
11 arthur.duff@example4.com Arthur Duff OR M Night table

21
tests/export-tsv.sh Normal file
View File

@ -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"

View File

@ -2,17 +2,17 @@
t="help"
# environment
# create tmp directory
tmpdir="$(mktemp -d)"
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
cd "${tmpdir}" || exit 1
# assertion
cat << "DATA" > "${t}.assert"
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

View File

@ -2,16 +2,20 @@
t="import-csv"
# environment
# create tmp directory
tmpdir="$(mktemp -d)"
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
cp data/example.csv "${tmpdir}"/${t}.csv
cp data/example.tsv "${tmpdir}"/${t}.assert
cd "${tmpdir}" || exit 1
# 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"
orcli export tsv "${t} csv" > "${t}.output"
# test
diff -u "${t}.assert" "${t}.output"

18
tests/info.sh Normal file
View File

@ -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"

18
tests/list.sh Normal file
View File

@ -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"

21
tests/run.sh Normal file
View File

@ -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"

19
tests/transform.sh Normal file
View File

@ -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"