From a09cc157ecd74967f8dddf65a68c81d71108265d Mon Sep 17 00:00:00 2001 From: redxef Date: Tue, 30 Aug 2022 23:24:55 +0200 Subject: [PATCH] Improve tests, use base32 to avoid illegal characters in file name. --- Makefile | 9 ++++++--- dvbackup | 2 +- test/mock-docker.sh | 6 ++++-- test/test.sh | 13 ++++--------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 254c3aa..1bdfbe0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/dvbackup b/dvbackup index 5551ed1..8a0b11b 100755 --- a/dvbackup +++ b/dvbackup @@ -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 } diff --git a/test/mock-docker.sh b/test/mock-docker.sh index c457764..8333e8c 100755 --- a/test/mock-docker.sh +++ b/test/mock-docker.sh @@ -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 } diff --git a/test/test.sh b/test/test.sh index ebbf680..673a767 100755 --- a/test/test.sh +++ b/test/test.sh @@ -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