restic/test/run.sh

92 lines
1.7 KiB
Bash
Raw Normal View History

2014-08-05 21:13:19 +00:00
#!/bin/bash
set -e
export khepri="${1:-khepri}"; shift
2014-08-06 18:09:51 +00:00
export dirdiff="${1:-dirdiff}"; shift
2014-08-05 21:13:19 +00:00
export dir=$(dirname "$0")
export fake_data_file="${dir}/fake-data.tar.gz"
prepare() {
export BASE="$(mktemp --tmpdir --directory khepri-testsuite-XXXXXX)"
export KHEPRI_REPOSITORY="${BASE}/khepri-backup"
export DATADIR="${BASE}/fake-data"
2014-09-23 20:39:12 +00:00
export KHEPRI_PASSWORD="foobar"
2014-08-05 21:13:19 +00:00
debug "repository is at ${KHEPRI_REPOSITORY}"
mkdir -p "$DATADIR"
(cd "$DATADIR"; tar xz) < "$fake_data_file"
debug "extracted fake data to ${DATADIR}"
}
cleanup() {
if [ "$DEBUG" = "1" ]; then
debug "leaving dir ${BASE}"
return
fi
rm -rf "${BASE}"
debug "removed dir ${BASE}"
unset BASE
unset KHEPRI_REPOSITORY
}
2014-08-06 18:09:51 +00:00
khepri() {
"${khepri}" "$@"
}
dirdiff() {
"${dirdiff}" "$@"
}
2014-08-05 21:13:19 +00:00
msg() {
printf "%s: %s\n" "$(basename "$0" .sh)" "$*"
}
pass() {
printf "\e[32m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*"
}
err() {
printf "\e[31m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*"
}
debug() {
if [ "$DEBUG" = "1" ]; then
printf "\e[33m%s: %s\e[39m\n" "$(basename "$0" .sh)" "$*"
fi
}
fail() {
err "$@"
exit 1
}
run() {
if [ "$DEBUG" = "1" ]; then
"$@"
else
"$@" > /dev/null
fi
}
2014-08-06 18:09:51 +00:00
export -f khepri dirdiff prepare cleanup msg debug pass err fail run
2014-08-05 21:13:19 +00:00
if [ ! -x "$khepri" ]; then
fail khepri binary not found!
fi
if [ "$#" -gt 0 ]; then
testfiles="$1"
else
testfiles=(${dir}/test-*.sh)
fi
echo "testfiles: $testfiles"
for testfile in "$testfiles"; do
current=$(basename "${testfile}" .sh)
2014-08-06 18:09:51 +00:00
bash "${testfile}" && pass "${current} pass" || err "${current} failed!"
2014-08-05 21:13:19 +00:00
done