dvbackup/test/test.sh

24 lines
792 B
Bash
Executable file

#!/usr/bin/env sh
cd "$(dirname "$0")" || exit 1
VOLUME_NAME="$(dd if=/dev/random bs=10 count=1 | base32)"
docker volume create "$VOLUME_NAME"
# shellcheck disable=SC2064
trap "docker volume rm $VOLUME_NAME && rm -f $VOLUME_NAME.tar" EXIT
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
sh -c 'echo "test" > /data/a.txt'
DOCKER=./mock-docker.sh DOCKER_MOCK_VOLUME="$VOLUME_NAME" \
../dvbackup backup_all
stat "$VOLUME_NAME.tar" || exit 1
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
sh -c 'rm /data/a.txt' || exit 1
DOCKER=./mock-docker.sh DOCKER_MOCK_VOLUME="$VOLUME_NAME" DVB_I_KNOW_WHAT_I_DO=y \
../dvbackup restore_all "$VOLUME_NAME.tar" || exit 1
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
sh -c 'stat /data/a.txt' || exit 1
exit 0