additional tests
This commit is contained in:
parent
56c9bbe21e
commit
40de708115
35
orcli
35
orcli
|
@ -1051,24 +1051,27 @@ orcli_test_command() {
|
||||||
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
|
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check existence of files
|
|
||||||
if ! [[ -f "tests/help.sh" ]]; then
|
|
||||||
error "Cannot open test files!"
|
|
||||||
fi
|
|
||||||
cd "tests"
|
|
||||||
files=(*.sh)
|
|
||||||
|
|
||||||
# create tmp directory
|
# create tmp directory
|
||||||
OPENREFINE_TMPDIR="$(mktemp -d)"
|
OPENREFINE_TMPDIR="$(mktemp -d)"
|
||||||
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
|
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
|
||||||
|
|
||||||
# check if OpenRefine is already running
|
# download the test files if needed
|
||||||
if curl -fs "${OPENREFINE_URL}" &>/dev/null; then
|
if ! [[ -f "tests/help.sh" ]]; then
|
||||||
error "OpenRefine is already running."
|
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
|
fi
|
||||||
|
|
||||||
# start OpenRefine with tmp workspace and autosave period 25 hours
|
# check if OpenRefine is already running
|
||||||
REFINE_AUTOSAVE_PERIOD=1440 $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" &
|
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="$!"
|
OPENREFINE_PID="$!"
|
||||||
|
|
||||||
# update trap to kill OpenRefine on error or exit
|
# update trap to kill OpenRefine on error or exit
|
||||||
|
@ -1081,11 +1084,13 @@ orcli_test_command() {
|
||||||
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
|
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# execute script(s) in subshell
|
# execute tests in subshell
|
||||||
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
|
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
|
||||||
|
cd "tests"
|
||||||
|
files=(*.sh)
|
||||||
results=()
|
results=()
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
set +e
|
set +e # do not exit on failed tests
|
||||||
bash -e <(
|
bash -e <(
|
||||||
if ! command -v orcli &>/dev/null; then
|
if ! command -v orcli &>/dev/null; then
|
||||||
echo "shopt -s expand_aliases"
|
echo "shopt -s expand_aliases"
|
||||||
|
@ -1103,7 +1108,7 @@ orcli_test_command() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# summary
|
# print overall result
|
||||||
if [[ "${results[*]}" =~ [1-9] ]]; then
|
if [[ "${results[*]}" =~ [1-9] ]]; then
|
||||||
error "failed tests!"
|
error "failed tests!"
|
||||||
else
|
else
|
||||||
|
|
|
@ -8,24 +8,27 @@ else
|
||||||
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
|
error "OpenRefine's startup script (refine) not found!" "Did you put orcli in your OpenRefine app dir?"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check existence of files
|
|
||||||
if ! [[ -f "tests/help.sh" ]]; then
|
|
||||||
error "Cannot open test files!"
|
|
||||||
fi
|
|
||||||
cd "tests"
|
|
||||||
files=(*.sh)
|
|
||||||
|
|
||||||
# create tmp directory
|
# create tmp directory
|
||||||
OPENREFINE_TMPDIR="$(mktemp -d)"
|
OPENREFINE_TMPDIR="$(mktemp -d)"
|
||||||
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
|
trap '{ rm -rf "$OPENREFINE_TMPDIR"; }' 0 2 3 15
|
||||||
|
|
||||||
# check if OpenRefine is already running
|
# download the test files if needed
|
||||||
if curl -fs "${OPENREFINE_URL}" &>/dev/null; then
|
if ! [[ -f "tests/help.sh" ]]; then
|
||||||
error "OpenRefine is already running."
|
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
|
fi
|
||||||
|
|
||||||
# start OpenRefine with tmp workspace and autosave period 25 hours
|
# check if OpenRefine is already running
|
||||||
REFINE_AUTOSAVE_PERIOD=1440 $openrefine -d "$OPENREFINE_TMPDIR" -x refine.headless=true -v warn &>"$OPENREFINE_TMPDIR/openrefine.log" &
|
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="$!"
|
OPENREFINE_PID="$!"
|
||||||
|
|
||||||
# update trap to kill OpenRefine on error or exit
|
# update trap to kill OpenRefine on error or exit
|
||||||
|
@ -38,11 +41,13 @@ else
|
||||||
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
|
log "started OpenRefine with tmp workspace ${OPENREFINE_TMPDIR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# execute script(s) in subshell
|
# execute tests in subshell
|
||||||
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
|
export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
|
||||||
|
cd "tests"
|
||||||
|
files=(*.sh)
|
||||||
results=()
|
results=()
|
||||||
for i in "${!files[@]}"; do
|
for i in "${!files[@]}"; do
|
||||||
set +e
|
set +e # do not exit on failed tests
|
||||||
bash -e <(
|
bash -e <(
|
||||||
if ! command -v orcli &>/dev/null; then
|
if ! command -v orcli &>/dev/null; then
|
||||||
echo "shopt -s expand_aliases"
|
echo "shopt -s expand_aliases"
|
||||||
|
@ -60,7 +65,7 @@ for i in "${!files[@]}"; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# summary
|
# print overall result
|
||||||
if [[ "${results[*]}" =~ [1-9] ]]; then
|
if [[ "${results[*]}" =~ [1-9] ]]; then
|
||||||
error "failed tests!"
|
error "failed tests!"
|
||||||
else
|
else
|
||||||
|
|
|
@ -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,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"
|
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
t="help"
|
t="help"
|
||||||
|
|
||||||
# environment
|
# create tmp directory
|
||||||
tmpdir="$(mktemp -d)"
|
tmpdir="$(mktemp -d)"
|
||||||
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
cd "${tmpdir}" || exit 1
|
|
||||||
|
|
||||||
# assertion
|
# assertion
|
||||||
cat << "DATA" > "${t}.assert"
|
cat << "DATA" > "${tmpdir}/${t}.assert"
|
||||||
orcli - OpenRefine command-line interface written in Bash
|
orcli - OpenRefine command-line interface written in Bash
|
||||||
DATA
|
DATA
|
||||||
|
|
||||||
# action
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
orcli --help | head -n1 > "${t}.output"
|
orcli --help | head -n1 > "${t}.output"
|
||||||
|
|
||||||
# test
|
# test
|
||||||
|
|
|
@ -2,16 +2,20 @@
|
||||||
|
|
||||||
t="import-csv"
|
t="import-csv"
|
||||||
|
|
||||||
# environment
|
# create tmp directory
|
||||||
tmpdir="$(mktemp -d)"
|
tmpdir="$(mktemp -d)"
|
||||||
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||||
cp data/example.csv "${tmpdir}"/${t}.csv
|
|
||||||
cp data/example.tsv "${tmpdir}"/${t}.assert
|
# input
|
||||||
cd "${tmpdir}" || exit 1
|
cp data/example.csv "${tmpdir}/${t}.csv"
|
||||||
|
|
||||||
|
# assertion
|
||||||
|
cp data/example.tsv "${tmpdir}/${t}.assert"
|
||||||
|
|
||||||
# action
|
# action
|
||||||
|
cd "${tmpdir}" || exit 1
|
||||||
orcli import csv "${t}.csv"
|
orcli import csv "${t}.csv"
|
||||||
orcli export tsv "${t} csv" --output "${t}.output"
|
orcli export tsv "${t} csv" > "${t}.output"
|
||||||
|
|
||||||
# test
|
# test
|
||||||
diff -u "${t}.assert" "${t}.output"
|
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