Refactor testsuite

This commit is contained in:
Alexander Neumann
2015-01-14 21:36:33 +01:00
parent 25a214809b
commit fb95f02af6
9 changed files with 52 additions and 49 deletions

Binary file not shown.

View File

@@ -1,104 +0,0 @@
#!/bin/bash
set -e
export dir=$(dirname "$0")
export fake_data_file="${dir}/fake-data.tar.gz"
prepare() {
export BASE="$(mktemp --tmpdir --directory restic-testsuite-XXXXXX)"
export RESTIC_REPOSITORY="${BASE}/restic-backup"
export RESTIC_PASSWORD="foobar"
export DATADIR="${BASE}/fake-data"
debug "repository is at ${RESTIC_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 RESTIC_REPOSITORY
}
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 prepare cleanup msg debug pass err fail run
# first argument is restic path
export PATH="$1:$PATH"; shift
which restic || fail "restic binary not found!"
which dirdiff || fail "dirdiff binary not found!"
debug "restic path: $(which restic)"
debug "dirdiff path: $(which dirdiff)"
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 [ "$DEBUG" = "1" ]; then
OPTS="-v"
fi
if bash $OPTS "${testfile}"; then
pass "${current} pass"
else
err "${current} failed!"
failed+=" ${current}"
fi
done
if [ -n "$failed" ]; then
err "failed tests: ${failed}"
msg "restic versions:"
run restic version
run restic.debug version
exit 1
fi

View File

@@ -1,16 +0,0 @@
set -em
# setup restic
prepare
run restic init
# start backup, break before saving files
DEBUG_BREAK=Archiver.Snapshot run restic.debug backup "${BASE}/fake-data" && debug "done"
# remove file
rm -f "${BASE}/fake-data/0/0/9/37"
# resume backup
fg
cleanup

View File

@@ -1,15 +0,0 @@
set -e
prepare
run restic init
run restic backup "${BASE}/fake-data"
run restic restore "$(basename "$RESTIC_REPOSITORY"/snapshots/*)" "${BASE}/fake-data-restore"
dirdiff "${BASE}/fake-data" "${BASE}/fake-data-restore/fake-data"
SNAPSHOT=$(run restic list snapshots)
run restic backup "${BASE}/fake-data" $SNAPSHOT
run restic restore "$(basename "$RESTIC_REPOSITORY"/snapshots/*)" "${BASE}/fake-data-restore-incremental"
dirdiff "${BASE}/fake-data" "${BASE}/fake-data-restore-incremental/fake-data"
run restic fsck -o --check-data
cleanup

View File

@@ -1,42 +0,0 @@
set -e
dump_repo() {
if [ "$FAILED" == "1" ]; then
tar cvz "$RESTIC_REPOSITORY" | base64 >&2
fi
}
FAILED=1
trap dump_repo 0
prepare
unset RESTIC_PASSWORD
RESTIC_PASSWORD=foo run restic init
RESTIC_PASSWORD=foo run restic key list
RESTIC_PASSWORD=foo RESTIC_NEWPASSWORD=foobar run restic key change
RESTIC_PASSWORD=foobar run restic key list
RESTIC_PASSWORD=foobar RESTIC_NEWPASSWORD=foo run restic key change
OLD_PWD=foo
for i in {1..3}; do
NEW_PWD=bar$i
RESTIC_PASSWORD=$OLD_PWD RESTIC_NEWPASSWORD=$NEW_PWD run restic key add
RESTIC_PASSWORD=$OLD_PWD run restic key list
RESTIC_PASSWORD=$NEW_PWD run restic key list
export RESTIC_PASSWORD=$OLD_PWD
ID=$(restic key list | grep '^\*'|cut -d ' ' -f 1| sed 's/^.//')
unset RESTIC_PASSWORD
RESTIC_PASSWORD=$NEW_PWD run restic key rm $ID
RESTIC_PASSWORD=$NEW_PWD run restic key list
OLD_PWD=bar$i
done
RESTIC_PASSWORD=$OLD_PWD run restic fsck -o --check-data
cleanup
FAILED=0