Improve tests, use base32 to avoid illegal characters in file name.
This commit is contained in:
parent
6f457fb7dd
commit
a09cc157ec
4 changed files with 15 additions and 15 deletions
9
Makefile
9
Makefile
|
@ -1,11 +1,14 @@
|
||||||
all: shellcheck
|
all: shellcheck test
|
||||||
|
|
||||||
shellcheck: shellcheck.log
|
shellcheck: shellcheck.log
|
||||||
|
|
||||||
install: dvbackup shellcheck
|
test:
|
||||||
|
./test/test.sh
|
||||||
|
|
||||||
|
install: dvbackup shellcheck test
|
||||||
install -Dm 0755 --owner=root --group=root $< /usr/local/bin/
|
install -Dm 0755 --owner=root --group=root $< /usr/local/bin/
|
||||||
|
|
||||||
shellcheck.log: dvbackup
|
shellcheck.log: dvbackup
|
||||||
shellcheck $< | tee $@
|
shellcheck $< | tee $@
|
||||||
|
|
||||||
.PHONY: all shellcheck install
|
.PHONY: all shellcheck test install
|
||||||
|
|
2
dvbackup
2
dvbackup
|
@ -65,7 +65,6 @@ restore_all() {
|
||||||
fi
|
fi
|
||||||
for tarball in "$@"; do
|
for tarball in "$@"; do
|
||||||
volume_name="${tarball%.tar}"
|
volume_name="${tarball%.tar}"
|
||||||
echo "$volume_name -> $volume"
|
|
||||||
if ! "$DOCKER" volume inspect "$volume_name" 1>&2 2>/dev/null; then
|
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
|
if echo "$DVB_CREATE_VOLUME" | grep -Eiq 't|true|1|y|yes'; then
|
||||||
"$DOCKER" volume create "$volume_name"
|
"$DOCKER" volume create "$volume_name"
|
||||||
|
@ -74,6 +73,7 @@ restore_all() {
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
echo "$tarball -> $volume_name"
|
||||||
restore "$tarball" "$volume_name"
|
restore "$tarball" "$volume_name"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,14 @@ volume() {
|
||||||
echo "local 00c674e3f3c1587d88c2ebf2f91da5843b9dddb3e8df272898bdfd4e596aef79"
|
echo "local 00c674e3f3c1587d88c2ebf2f91da5843b9dddb3e8df272898bdfd4e596aef79"
|
||||||
echo "local $DOCKER_MOCK_VOLUME"
|
echo "local $DOCKER_MOCK_VOLUME"
|
||||||
return 0
|
return 0
|
||||||
elif [ "$2" = 'inspect' ]; then
|
elif [ "$1" = 'inspect' ]; then
|
||||||
if [ "$3" = "$DOCKER_MOCK_VOLUME" ]; then
|
if [ "$2" = "$DOCKER_MOCK_VOLUME" ]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
docker volume "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
test/test.sh
13
test/test.sh
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
cd "$(dirname "$0")" || exit 1
|
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"
|
docker volume create "$VOLUME_NAME"
|
||||||
|
|
||||||
# shellcheck disable=SC2064
|
# 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 \
|
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
|
||||||
sh -c 'echo "test" > /data/a.txt'
|
sh -c 'echo "test" > /data/a.txt'
|
||||||
DOCKER=./mock-docker.sh DOCKER_MOCK_VOLUME="$VOLUME_NAME" \
|
DOCKER=./mock-docker.sh DOCKER_MOCK_VOLUME="$VOLUME_NAME" \
|
||||||
../dvbackup.sh backup_all
|
../dvbackup backup_all
|
||||||
stat "$VOLUME_NAME.tar" || exit 1
|
stat "$VOLUME_NAME.tar" || exit 1
|
||||||
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
|
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
|
||||||
sh -c 'rm /data/a.txt' || exit 1
|
sh -c 'rm /data/a.txt' || exit 1
|
||||||
DOCKER=./mock-docker.sh DOCKER_MOCK_VOLUME="$VOLUME_NAME" \
|
DOCKER=./mock-docker.sh DOCKER_MOCK_VOLUME="$VOLUME_NAME" DVB_I_KNOW_WHAT_I_DO=y \
|
||||||
../dvbackup.sh restore_all "$VOLUME_NAME.tar" || exit 1
|
../dvbackup restore_all "$VOLUME_NAME.tar" || exit 1
|
||||||
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
|
docker run --rm --volume="$VOLUME_NAME:/data" alpine \
|
||||||
sh -c 'stat /data/a.txt' || exit 1
|
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
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue