From 10e93a2f6c5d2f12572d77caaeb57cb53a8d712c Mon Sep 17 00:00:00 2001 From: James Tufarelli Date: Tue, 24 Oct 2023 17:31:27 -0700 Subject: [PATCH] Add test_override_dest test --- pkg/env.sh | 2 +- tests/tests.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/pkg/env.sh b/pkg/env.sh index 3ab0bb89..2b3c4195 100755 --- a/pkg/env.sh +++ b/pkg/env.sh @@ -182,7 +182,7 @@ else fi export OVERRIDE_SOURCE_DIR -if [ ! -z "$OVERRIDE_DEST_DIR" ]; then +if [ -z "$OVERRIDE_DEST_DIR" ]; then OVERRIDE_DEST_DIR=$DEFAULT_OVERRIDE_DEST_DIR else logThis "OVERRIDE_DEST_DIR: $OVERRIDE_DEST_DIR" "DEBUG" "init" diff --git a/tests/tests.sh b/tests/tests.sh index da3895f4..a3883ac8 100755 --- a/tests/tests.sh +++ b/tests/tests.sh @@ -517,9 +517,15 @@ test_override_src() { echo "-ahq tests/src/container3-new/ tests/dest/container3-new/" ) + disallowed_rsync_output=$( + echo "-ahq tests/src/container1/ tests/dest/container1/" && + echo "-ahq tests/src/container3/ tests/dest/container3/" + ) + test_rsync \ - --name "Test Global Source override" \ + --name "Test Source override (env)" \ --mock_ps "$mock_docker_ps_lines" \ + --disallow "$disallowed_rsync_output" \ --expect "$expected_rsync_output" cleanup_on_success @@ -536,11 +542,73 @@ test_override_src() { expected_rsync_output=$( echo "-ahq tests/src/container-override/ tests/dest/container-override/" ) + disallowed_rsync_output=$( + echo "-ahq tests/src/container1/ tests/dest/container1/" + ) + + test_rsync \ + --name "Test Source override (label)" \ + --mock_ps "$mock_docker_ps_lines" \ + --expect "$expected_rsync_output" \ + --disallow "$disallowed_rsync_output" \ + --mock_labels "$mock_docker_label_lines" + + reset_environment_variables +} + +test_override_dest() { + clear_files + export BACKUP_ON_START="true" + export OVERRIDE_DEST_DIR=container1:container1-override,container2:container2-override,container3:container3-new + mkdir -p tests/src/container1 && touch tests/src/container1/test.txt + mkdir -p tests/src/container3 && touch tests/src/container3/test.txt + mkdir -p tests/dest + + mock_docker_ps_lines=$( + echo "abc123:container1" && + echo "def456:container2" && + echo "ghi789:container3" + ) + + expected_rsync_output=$( + echo "-ahq tests/src/container1/ tests/dest/container1-override/" && + echo "-ahq tests/src/container3/ tests/dest/container3-new/" + ) + + disallowed_rsync_output=$( + echo "-ahq tests/src/container1/ tests/dest/container1/" && + echo "-ahq tests/src/container3/ tests/dest/container3/" + ) + + test_rsync \ + --name "Test Destination override (env)" \ + --mock_ps "$mock_docker_ps_lines" \ + --disallow "$disallowed_rsync_output" \ + --expect "$expected_rsync_output" + + cleanup_on_success + mkdir -p tests/src/container1 && touch tests/src/container1/test.txt + mkdir -p tests/dest + + mock_docker_ps_lines=$( + echo "abc123:container1" + ) + + mock_docker_label_lines=$( + echo "{\"nautical-backup.override-destination-dir\":\"container-override\"}" + ) + expected_rsync_output=$( + echo "-ahq tests/src/container1/ tests/dest/container-override/" + ) + disallowed_rsync_output=$( + echo "-ahq tests/src/container1/ tests/dest/container1/" + ) test_rsync \ - --name "Test Label Source override" \ + --name "Test Destination override (label)" \ --mock_ps "$mock_docker_ps_lines" \ --expect "$expected_rsync_output" \ + --disallow "$disallowed_rsync_output" \ --mock_labels "$mock_docker_label_lines" } @@ -554,6 +622,7 @@ test_skip_containers test_enable_label test_require_label test_override_src +test_override_dest # Cleanup teardown