Fix docker tests to use actual volumes.

This commit is contained in:
redxef 2023-06-07 23:54:52 +02:00
parent d13519229b
commit cbd8e4cb09
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921
4 changed files with 60 additions and 35 deletions

View file

@ -1,9 +1,5 @@
#!/bin/sh #!/bin/sh
_tarback_plugin_docker_cmd='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine ' _tarback_plugin_docker_cmd='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine '
TARBACK_TAR_CREATE_COMMAND="$_tarback_plugin_docker_cmd "'tar c -C "/mnt/$1" .'
TARBACK_TAR_EXTRACT_COMMAND="$_tarback_plugin_docker_cmd "'tar x -C "/mnt/$1"'
# Can set file to same as directory command since a docker volume is always a directory
TARBACK_TAR_CREATE_COMMAND_FILE="$_tarback_plugin_docker_cmd "'tar c -C "/mnt/$1" .' TARBACK_TAR_CREATE_COMMAND_FILE="$_tarback_plugin_docker_cmd "'tar c -C "/mnt/$1" .'
TARBACK_TAR_EXTRACT_COMMAND_FILE="$_tarback_plugin_docker_cmd "'tar x -C "/mnt/$1"' TARBACK_TAR_EXTRACT_COMMAND_FILE="$_tarback_plugin_docker_cmd "'tar x -C "/mnt/$1"'

View file

@ -5,9 +5,34 @@ create_directories() {
mkdir -p "$workdir/source" mkdir -p "$workdir/source"
mkdir -p "$workdir/dest" mkdir -p "$workdir/dest"
mkdir -p "$workdir/restore" mkdir -p "$workdir/restore"
if [ $# -eq 1 ]; then
filename_len=$1
else
filename_len=255
fi
# generate a filename with every possible byte in it to test # generate a filename with every possible byte in it to test
# escaping, the only character not included is `/` since that is # escaping, the only character not included is `/` since that is
# illegal for filenames (obviously) # illegal for filenames (obviously)
echo 'Hello World!' > "$workdir/source/$(for i in $(seq 0 255); do printf '%x' "$i" | xxd -r -p; done | tr -d '/')" echo 'Hello World!' > "$workdir/source/$(for i in $(seq 0 $filename_len); do printf '%x' "$i" | xxd -r -p; done | tr -d '/')"
echo "$workdir" echo "$workdir"
} }
create_docker_volume() {
volumename="tarback-docker-volume-test-$(shuf -i 1000-9999 -n 1)"
# use shorter name because alpine runs into a filename length limit
if [ $# -eq 2 ]; then
workdir="$1"
filename="$2"
docker run --rm -i -v "$volumename:/mnt" alpine tee "/mnt/$filename" < "$workdir/source/$filename" 1>/dev/null
fi
echo "$volumename"
}
extract_docker_volume() {
volumename="$1"
workdir="$2"
filename="$3"
#docker run --rm -v "$volumename:/mnt" alpine find /
docker run --rm -v "$volumename:/mnt" alpine cat "/mnt/$filename" > "$workdir/restore/$filename"
}

View file

@ -5,25 +5,27 @@ set -eu
. ./tests/common.sh . ./tests/common.sh
# archive whole directory # archive whole directory
workdir="$(create_directories)" workdir="$(create_directories 127)"
./tarback.sh -p docker create "$workdir/source" "$workdir/dest/source.tar.xz" filename="$(basename "$(find "$workdir/source" -type f)")"
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore" docker_volume="$(create_docker_volume "$workdir" "$filename")"
./tarback.sh -p docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore" diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
rm -rf "$workdir" rm -rf "$workdir"
# archive single file workdir="$(create_directories 127)"
workdir="$(create_directories)"
filename="$(basename "$(find "$workdir/source" -type f)")" filename="$(basename "$(find "$workdir/source" -type f)")"
./tarback.sh -p docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz" docker_volume="$(create_docker_volume "$workdir" "$filename")"
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename" TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore" diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
rm -rf "$workdir" rm -rf "$workdir"
# split archive
workdir="$(create_directories)"
filename="$(basename "$(find "$workdir/source" -type f)")"
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
diff "$workdir/source" "$workdir/restore"
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
rm -rf "$workdir"

View file

@ -7,25 +7,27 @@ set -eu
export TARBACK_REMOTE='ssh localhost' export TARBACK_REMOTE='ssh localhost'
# archive whole directory # archive whole directory
workdir="$(create_directories)" workdir="$(create_directories 127)"
./tarback.sh -p ssh,docker create "$workdir/source" "$workdir/dest/source.tar.xz" filename="$(basename "$(find "$workdir/source" -type f)")"
./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$workdir/restore" docker_volume="$(create_docker_volume "$workdir" "$filename")"
./tarback.sh -p ssh,docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore" diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
rm -rf "$workdir" rm -rf "$workdir"
# archive single file workdir="$(create_directories 127)"
workdir="$(create_directories)"
filename="$(basename "$(find "$workdir/source" -type f)")" filename="$(basename "$(find "$workdir/source" -type f)")"
./tarback.sh -p ssh,docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz" docker_volume="$(create_docker_volume "$workdir" "$filename")"
./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename" TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p ssh,docker create "$docker_volume" "$workdir/dest/source.tar.xz"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
docker_volume="$(create_docker_volume)"
TARBACK_SPLIT='split -b 10 -' ./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$docker_volume"
extract_docker_volume "$docker_volume" "$workdir" "$filename"
diff "$workdir/source" "$workdir/restore" diff "$workdir/source" "$workdir/restore"
docker volume rm "$docker_volume" 2>/dev/null 1>&2
rm -rf "$workdir" rm -rf "$workdir"
# split archive
workdir="$(create_directories)"
filename="$(basename "$(find "$workdir/source" -type f)")"
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p ssh,docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
diff "$workdir/source" "$workdir/restore"
[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ]
rm -rf "$workdir"