2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-25 06:07:44 +00:00
restic/test/run.sh

103 lines
1.8 KiB
Bash
Raw Normal View History

2014-08-05 21:13:19 +00:00
#!/bin/bash
set -e
2014-12-05 20:45:49 +00:00
export restic="${1:-restic}"; 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() {
2014-12-05 20:45:49 +00:00
export BASE="$(mktemp --tmpdir --directory restic-testsuite-XXXXXX)"
export RESTIC_REPOSITORY="${BASE}/restic-backup"
2014-08-05 21:13:19 +00:00
export DATADIR="${BASE}/fake-data"
2014-12-05 20:45:49 +00:00
export RESTIC_PASSWORD="foobar"
debug "repository is at ${RESTIC_REPOSITORY}"
2014-08-05 21:13:19 +00:00
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
2014-12-05 20:45:49 +00:00
unset RESTIC_REPOSITORY
2014-08-05 21:13:19 +00:00
}
2014-12-05 20:45:49 +00:00
restic() {
"${restic}" "$@"
2014-08-06 18:09:51 +00:00
}
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-12-05 20:45:49 +00:00
export -f restic dirdiff prepare cleanup msg debug pass err fail run
2014-08-05 21:13:19 +00:00
2014-12-05 20:45:49 +00:00
if [ ! -x "$restic" ]; then
fail restic binary not found!
2014-08-05 21:13:19 +00:00
fi
if [ "$#" -gt 0 ]; then
testfiles="$1"
else
testfiles=(${dir}/test-*.sh)
fi
2014-11-27 23:34:56 +00:00
echo "testfiles: ${testfiles[@]}"
2014-08-05 21:13:19 +00:00
failed=""
2014-11-27 23:34:56 +00:00
for testfile in "${testfiles[@]}"; do
2014-08-05 21:13:19 +00:00
current=$(basename "${testfile}" .sh)
if bash "${testfile}"; then
pass "${current} pass"
else
err "${current} failed!"
failed+=" ${current}"
fi
2014-08-05 21:13:19 +00:00
done
if [ -n "$failed" ]; then
err "failed tests: ${failed}"
exit 1
fi