2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-05 04:47:51 +00:00
restic/test/run.sh
2014-11-16 11:34:16 +01:00

103 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
set -e
export khepri="${1:-khepri}"; shift
export dirdiff="${1:-dirdiff}"; shift
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"
export KHEPRI_PASSWORD="foobar"
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
}
khepri() {
"${khepri}" "$@"
}
dirdiff() {
"${dirdiff}" "$@"
}
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
}
export -f khepri dirdiff prepare cleanup msg debug pass err fail run
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"
failed=""
for testfile in "$testfiles"; do
current=$(basename "${testfile}" .sh)
if bash "${testfile}"; then
pass "${current} pass"
else
err "${current} failed!"
failed+=" ${current}"
fi
done
if [ -n "$failed" ]; then
err "failed tests: ${failed}"
exit 1
fi