Fix docker tests to use actual volumes.
This commit is contained in:
parent
d13519229b
commit
cbd8e4cb09
4 changed files with 60 additions and 35 deletions
|
@ -1,9 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
_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_EXTRACT_COMMAND_FILE="$_tarback_plugin_docker_cmd "'tar x -C "/mnt/$1"'
|
||||
|
|
|
@ -5,9 +5,34 @@ create_directories() {
|
|||
mkdir -p "$workdir/source"
|
||||
mkdir -p "$workdir/dest"
|
||||
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
|
||||
# escaping, the only character not included is `/` since that is
|
||||
# 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"
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
|
|
@ -5,25 +5,27 @@ set -eu
|
|||
. ./tests/common.sh
|
||||
|
||||
# archive whole directory
|
||||
workdir="$(create_directories)"
|
||||
./tarback.sh -p docker create "$workdir/source" "$workdir/dest/source.tar.xz"
|
||||
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore"
|
||||
workdir="$(create_directories 127)"
|
||||
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||
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"
|
||||
docker volume rm "$docker_volume" 2>/dev/null 1>&2
|
||||
rm -rf "$workdir"
|
||||
|
||||
# archive single file
|
||||
workdir="$(create_directories)"
|
||||
workdir="$(create_directories 127)"
|
||||
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||
./tarback.sh -p docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||
./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||
docker_volume="$(create_docker_volume "$workdir" "$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"
|
||||
docker volume rm "$docker_volume" 2>/dev/null 1>&2
|
||||
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"
|
||||
|
|
|
@ -7,25 +7,27 @@ set -eu
|
|||
export TARBACK_REMOTE='ssh localhost'
|
||||
|
||||
# archive whole directory
|
||||
workdir="$(create_directories)"
|
||||
./tarback.sh -p ssh,docker create "$workdir/source" "$workdir/dest/source.tar.xz"
|
||||
./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$workdir/restore"
|
||||
workdir="$(create_directories 127)"
|
||||
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||
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"
|
||||
docker volume rm "$docker_volume" 2>/dev/null 1>&2
|
||||
rm -rf "$workdir"
|
||||
|
||||
# archive single file
|
||||
workdir="$(create_directories)"
|
||||
workdir="$(create_directories 127)"
|
||||
filename="$(basename "$(find "$workdir/source" -type f)")"
|
||||
./tarback.sh -p ssh,docker create "$workdir/source/$filename" "$workdir/dest/source.tar.xz"
|
||||
./tarback.sh -p ssh,docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/$filename"
|
||||
docker_volume="$(create_docker_volume "$workdir" "$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"
|
||||
docker volume rm "$docker_volume" 2>/dev/null 1>&2
|
||||
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"
|
||||
|
|
Loading…
Reference in a new issue