mirror of
https://github.com/restic/restic.git
synced 2024-12-22 07:43:03 +00:00
Add Makefiles and simple test suite
This commit is contained in:
parent
f45a9c8e9f
commit
ab602b88de
5 changed files with 112 additions and 0 deletions
10
Makefile
Normal file
10
Makefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
.PHONY: clean all test
|
||||
|
||||
test:
|
||||
go test
|
||||
$(MAKE) -C cmd/khepri
|
||||
test/run.sh cmd/khepri/khepri
|
||||
|
||||
clean:
|
||||
go clean
|
||||
$(MAKE) -C cmd/khepri test
|
7
cmd/khepri/Makefile
Normal file
7
cmd/khepri/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
.PHONY: clean all test
|
||||
|
||||
test:
|
||||
go build
|
||||
|
||||
clean:
|
||||
go clean
|
BIN
test/fake-data.tar.gz
Normal file
BIN
test/fake-data.tar.gz
Normal file
Binary file not shown.
90
test/run.sh
Executable file
90
test/run.sh
Executable file
|
@ -0,0 +1,90 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
export khepri="${1:-khepri}"; shift
|
||||
export dir=$(dirname "$0")
|
||||
export fake_data_file="${dir}/fake-data.tar.gz"
|
||||
|
||||
k() {
|
||||
"${khepri}" "$@"
|
||||
}
|
||||
|
||||
prepare() {
|
||||
export BASE="$(mktemp --tmpdir --directory khepri-testsuite-XXXXXX)"
|
||||
export KHEPRI_REPOSITORY="${BASE}/khepri-backup"
|
||||
export DATADIR="${BASE}/fake-data"
|
||||
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
|
||||
}
|
||||
|
||||
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 k 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"
|
||||
|
||||
for testfile in "$testfiles"; do
|
||||
current=$(basename "${testfile}" .sh)
|
||||
|
||||
bash "${testfile}"
|
||||
if [ "$?" != "0" ]; then
|
||||
err "${current} failed!"
|
||||
else
|
||||
pass "${current} pass"
|
||||
fi
|
||||
done
|
5
test/test-backup.sh
Executable file
5
test/test-backup.sh
Executable file
|
@ -0,0 +1,5 @@
|
|||
prepare
|
||||
run k backup "${BASE}/fake-data"
|
||||
run k restore "$(k list ref)" "${BASE}/fake-data-restore"
|
||||
diff -aur "${BASE}/fake-data" "${BASE}/fake-data-restore"
|
||||
cleanup
|
Loading…
Reference in a new issue