Improve tests, use base32 to avoid illegal characters in file name.

This commit is contained in:
redxef 2022-08-30 23:24:55 +02:00
parent 6f457fb7dd
commit a09cc157ec
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
4 changed files with 15 additions and 15 deletions

View file

@ -1,11 +1,14 @@
all: shellcheck
all: shellcheck test
shellcheck: shellcheck.log
install: dvbackup shellcheck
test:
./test/test.sh
install: dvbackup shellcheck test
install -Dm 0755 --owner=root --group=root $< /usr/local/bin/
shellcheck.log: dvbackup
shellcheck $< | tee $@
.PHONY: all shellcheck install
.PHONY: all shellcheck test install

View file

@ -65,7 +65,6 @@ restore_all() {
fi
for tarball in "$@"; do
volume_name="${tarball%.tar}"
echo "$volume_name -> $volume"
if ! "$DOCKER" volume inspect "$volume_name" 1>&2 2>/dev/null; then
if echo "$DVB_CREATE_VOLUME" | grep -Eiq 't|true|1|y|yes'; then
"$DOCKER" volume create "$volume_name"
@ -74,6 +73,7 @@ restore_all() {
exit 4
fi
fi
echo "$tarball -> $volume_name"
restore "$tarball" "$volume_name"
done
}

View file

@ -6,12 +6,14 @@ volume() {
echo "local 00c674e3f3c1587d88c2ebf2f91da5843b9dddb3e8df272898bdfd4e596aef79"
echo "local $DOCKER_MOCK_VOLUME"
return 0
elif [ "$2" = 'inspect' ]; then
if [ "$3" = "$DOCKER_MOCK_VOLUME" ]; then
elif [ "$1" = 'inspect' ]; then
if [ "$2" = "$DOCKER_MOCK_VOLUME" ]; then
return 0
else
return 1
fi
else
docker volume "$@"
fi
}

View file

@ -3,7 +3,7 @@
cd "$(dirname "$0")" || exit 1
VOLUME_NAME="$(dd if=/dev/random bs=6 count=1 | base64)"
VOLUME_NAME="$(dd if=/dev/random bs=10 count=1 | base32)"
docker volume create "$VOLUME_NAME"
# shellcheck disable=SC2064
@ -12,18 +12,13 @@ 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.sh backup_all
../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" \
../dvbackup.sh restore_all "$VOLUME_NAME.tar" || 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
DOCKER=./mock-docker.sh DOCKER_MOCK_VOLUME="$VOLUME_NAME-0" \
../dvbackup.sh restore_all "$VOLUME_NAME-0.tar" || exit 1
docker run --rm --volume="$VOLUME_NAME-0:/data" alpine \
sh -c 'stat /data/a.txt' || exit 1
exit 0