2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-17 10:35:17 +00:00
restic/testsuite/run.sh

118 lines
2.2 KiB
Bash
Raw Normal View History

2014-08-05 21:13:19 +00:00
#!/bin/bash
set -e
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"
export RESTIC_PASSWORD="foobar"
export DATADIR="${BASE}/fake-data"
2014-12-05 20:45:49 +00:00
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
}
msg() {
2015-01-14 20:36:33 +00:00
printf "%s\n" "$*"
2014-08-05 21:13:19 +00:00
}
pass() {
2015-01-14 20:36:33 +00:00
printf "\e[32m%s\e[39m\n" "$*"
2014-08-05 21:13:19 +00:00
}
err() {
2015-01-14 20:36:33 +00:00
printf "\e[31m%s\e[39m\n" "$*"
2014-08-05 21:13:19 +00:00
}
debug() {
if [ "$DEBUG" = "1" ]; then
2015-01-14 20:36:33 +00:00
printf "\e[33m%s\e[39m\n" "$*"
2014-08-05 21:13:19 +00:00
fi
}
fail() {
err "$@"
exit 1
}
run() {
if [ "$DEBUG" = "1" ]; then
"$@"
else
"$@" > /dev/null
fi
}
export -f prepare cleanup msg debug pass err fail run
2014-08-05 21:13:19 +00:00
2015-01-14 20:36:33 +00:00
if [ -z "$BASEDIR" ]; then
echo "BASEDIR not set" >&2
exit 2
fi
2015-01-14 20:36:33 +00:00
which restic > /dev/null || fail "restic binary not found!"
which restic.debug > /dev/null || fail "restic.debug binary not found!"
which dirdiff > /dev/null || fail "dirdiff binary not found!"
debug "restic path: $(which restic)"
2015-01-14 20:36:33 +00:00
debug "restic.debug path: $(which restic.debug)"
debug "dirdiff path: $(which dirdiff)"
2015-01-14 20:36:33 +00:00
debug "path: $PATH"
debug "restic versions:"
run restic version
run restic.debug version
2014-08-05 21:13:19 +00:00
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
2015-01-14 20:36:33 +00:00
msg "================================================================================"
msg "run test $testfile"
msg ""
2014-08-05 21:13:19 +00:00
current=$(basename "${testfile}" .sh)
if [ "$DEBUG" = "1" ]; then
OPTS="-v"
fi
if bash $OPTS "${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}"
2015-01-14 21:08:48 +00:00
msg "restic versions:"
run restic version
run restic.debug version
exit 1
fi