From f272f2a14c60ef853bb860c0612ad931d5a21d74 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 29 Jan 2026 12:18:12 -0600 Subject: Add SSH remote backup support, new commands, and test suite - Add remote mode for SSH-based backups to servers like TrueNAS - Add SSH_IDENTITY_FILE config for non-root SSH keys - Add new commands: backup, status, list, dryrun - Add dependency checks for rsync, ssh, flock - Add timestamped logging - Fix: duplicate cron jobs on repeated setup - Fix: use mktemp for temp files - Fix: use portable sed instead of grep -oP - Fix: strengthen input validation with regex anchors - Fix: handle paths with spaces (newline-separated includes) - Change license from MIT to GPL v3 - Add automated test suite (25 tests) - Update README with new features and testing docs --- tests/cases/test_dryrun.sh | 120 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100755 tests/cases/test_dryrun.sh (limited to 'tests/cases/test_dryrun.sh') diff --git a/tests/cases/test_dryrun.sh b/tests/cases/test_dryrun.sh new file mode 100755 index 0000000..bff45e1 --- /dev/null +++ b/tests/cases/test_dryrun.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +# ============================================================================== +# Dry-Run Mode Tests +# ============================================================================== + +source "$(dirname "${BASH_SOURCE[0]}")/../lib/test_helpers.sh" + +# ------------------------------------------------------------------------------ +# Test: Dry-run doesn't create backup directory +# ------------------------------------------------------------------------------ +test_dryrun_no_directory_creation() { + setup_test_env + + create_test_config + create_test_includes + create_test_excludes + + # Remove backup dir to verify it's not created + rmdir "$TEST_BACKUP_DIR" + + local output + output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1) + + # Backup directory should NOT be created in dry-run mode + assert_dir_not_exists "$TEST_BACKUP_DIR/$HOSTNAME" "backup dir should not be created in dryrun" || { + teardown_test_env + return 1 + } + + teardown_test_env +} + +# ------------------------------------------------------------------------------ +# Test: Dry-run shows what would be transferred +# ------------------------------------------------------------------------------ +test_dryrun_shows_transfer_info() { + setup_test_env + + create_test_config + create_test_includes + create_test_excludes + + # Create the backup directory structure for dryrun to work + mkdir -p "$TEST_BACKUP_DIR/$HOSTNAME/latest" + + local output + output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1) + + teardown_test_env + + # Should show syncing messages + assert_contains "$output" "Syncing" "should show syncing info" || return 1 + # Should show dry run message + assert_contains "$output" "Dry run complete" "should show dryrun complete message" || return 1 +} + +# ------------------------------------------------------------------------------ +# Test: Dry-run shows command to run actual backup +# ------------------------------------------------------------------------------ +test_dryrun_shows_actual_command() { + setup_test_env + + create_test_config + create_test_includes + create_test_excludes + + mkdir -p "$TEST_BACKUP_DIR/$HOSTNAME/latest" + + local output + output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1) + + teardown_test_env + + # Should show how to run actual backup + assert_contains "$output" "sudo rsyncshot manual 1" "should show actual command" || return 1 +} + +# ------------------------------------------------------------------------------ +# Test: Dry-run doesn't create snapshots +# ------------------------------------------------------------------------------ +test_dryrun_no_snapshot_creation() { + setup_test_env + + create_test_config + create_test_includes + create_test_excludes + + mkdir -p "$TEST_BACKUP_DIR/$HOSTNAME/latest" + + local output + output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1) + + # Should not create manual.0 snapshot + assert_dir_not_exists "$TEST_BACKUP_DIR/$HOSTNAME/manual.0" "snapshot should not be created in dryrun" || { + teardown_test_env + return 1 + } + + teardown_test_env +} + +# ------------------------------------------------------------------------------ +# Run tests +# ------------------------------------------------------------------------------ +run_dryrun_tests() { + echo "" + echo "Running dry-run tests..." + echo "------------------------------------------------------------" + + run_test "dry-run doesn't create backup directory" test_dryrun_no_directory_creation + run_test "dry-run shows transfer info" test_dryrun_shows_transfer_info + run_test "dry-run shows actual command" test_dryrun_shows_actual_command + run_test "dry-run doesn't create snapshots" test_dryrun_no_snapshot_creation +} + +# Run if executed directly +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + run_dryrun_tests + print_summary +fi -- cgit v1.2.3