From 0e6fbcc6f1f1f4de57dc7002db5232d7b86ed3b9 Mon Sep 17 00:00:00 2001 From: redxef Date: Wed, 7 Jun 2023 15:26:01 +0200 Subject: [PATCH] Fix docker plugin, add ssh and docker tests. --- tarback/docker.sh | 5 +++-- tests/test-001-ssh.sh | 29 +++++++++++++++++++++++++++++ tests/test-002-docker.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100755 tests/test-001-ssh.sh create mode 100755 tests/test-002-docker.sh diff --git a/tarback/docker.sh b/tarback/docker.sh index 2d6a92b..64fa1aa 100644 --- a/tarback/docker.sh +++ b/tarback/docker.sh @@ -1,4 +1,5 @@ #!/bin/sh -TARBACK_TAR_CREATE_COMMAND='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine '"$TARBACK_TAR_CREATE_COMMAND" -TARBACK_TAR_EXTRACT_COMMAND='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine '"$TARBACK_TAR_EXTRACT_COMMAND" +_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"' diff --git a/tests/test-001-ssh.sh b/tests/test-001-ssh.sh new file mode 100755 index 0000000..42e3c3b --- /dev/null +++ b/tests/test-001-ssh.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -eu + +. ./tests/common.sh + +export TARBACK_REMOTE='ssh localhost' + +# archive whole directory +workdir="$(create_directories)" +./tarback.sh create "$workdir/source" "$workdir/dest/source.tar.xz" +./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore" +diff "$workdir/source" "$workdir/restore" +rm -rf "$workdir" + +# archive single file +workdir="$(create_directories)" +./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz" +./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt" +diff "$workdir/source" "$workdir/restore" +rm -rf "$workdir" + +# split archive +workdir="$(create_directories)" +TARBACK_SPLIT="split -b 10 -" ./tarback.sh create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz" +TARBACK_SPLIT="split -b 10 -" ./tarback.sh restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt" +diff "$workdir/source" "$workdir/restore" +[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ] +rm -rf "$workdir" diff --git a/tests/test-002-docker.sh b/tests/test-002-docker.sh new file mode 100755 index 0000000..da25aae --- /dev/null +++ b/tests/test-002-docker.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +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" +diff "$workdir/source" "$workdir/restore" +rm -rf "$workdir" + +# archive single file +workdir="$(create_directories)" +./tarback.sh -p docker create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz" +./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt" +diff "$workdir/source" "$workdir/restore" +rm -rf "$workdir" + +# split archive +workdir="$(create_directories)" +TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker create "$workdir/source/hello_world.txt" "$workdir/dest/source.tar.xz" +TARBACK_SPLIT="split -b 10 -" ./tarback.sh -p docker restore "$workdir/dest/source.tar.xz" "$workdir/restore/hello_world.txt" +diff "$workdir/source" "$workdir/restore" +[ "$(ls -1 "$workdir/dest/"*.part* | wc -l)" -gt 1 ] +rm -rf "$workdir"