aboutsummaryrefslogtreecommitdiff
path: root/tests/cases/test_includes.sh
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-01-29 12:18:12 -0600
committerCraig Jennings <c@cjennings.net>2026-01-29 12:18:12 -0600
commitf272f2a14c60ef853bb860c0612ad931d5a21d74 (patch)
treeae07730fa28db2309c524c00fd2689d934252aa4 /tests/cases/test_includes.sh
parent2bc8c5c7b416d506e9c46d9f381c73f5f9f052b9 (diff)
downloadrsyncshot-f272f2a14c60ef853bb860c0612ad931d5a21d74.tar.gz
rsyncshot-f272f2a14c60ef853bb860c0612ad931d5a21d74.zip
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
Diffstat (limited to 'tests/cases/test_includes.sh')
-rwxr-xr-xtests/cases/test_includes.sh161
1 files changed, 161 insertions, 0 deletions
diff --git a/tests/cases/test_includes.sh b/tests/cases/test_includes.sh
new file mode 100755
index 0000000..8f556e3
--- /dev/null
+++ b/tests/cases/test_includes.sh
@@ -0,0 +1,161 @@
+#!/usr/bin/env bash
+# ==============================================================================
+# Include File Parsing Tests
+# ==============================================================================
+
+source "$(dirname "${BASH_SOURCE[0]}")/../lib/test_helpers.sh"
+
+# ------------------------------------------------------------------------------
+# Test: Reads newline-separated paths
+# ------------------------------------------------------------------------------
+test_reads_newline_paths() {
+ setup_test_env
+
+ # Create config and include files
+ create_test_config
+ create_test_excludes
+
+ # Create include file with newline-separated paths
+ cat > "$TEST_CONFIG_DIR/include.txt" << EOF
+$TEST_SOURCE_DIR/home
+$TEST_SOURCE_DIR/etc
+EOF
+
+ # Run dryrun to test parsing
+ local output
+ output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
+ local exit_code=$?
+
+ teardown_test_env
+
+ # Should process both directories
+ assert_contains "$output" "Syncing $TEST_SOURCE_DIR/home" "should sync home" || return 1
+ assert_contains "$output" "Syncing $TEST_SOURCE_DIR/etc" "should sync etc" || return 1
+}
+
+# ------------------------------------------------------------------------------
+# Test: Skips comment lines
+# ------------------------------------------------------------------------------
+test_skips_comments() {
+ setup_test_env
+
+ create_test_config
+ create_test_excludes
+
+ # Create include file with comments
+ cat > "$TEST_CONFIG_DIR/include.txt" << EOF
+# This is a comment
+$TEST_SOURCE_DIR/home
+# Another comment
+$TEST_SOURCE_DIR/etc
+EOF
+
+ local output
+ output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
+
+ teardown_test_env
+
+ # Should not try to sync comment lines
+ assert_not_contains "$output" "Syncing # This" "should skip comments" || return 1
+ assert_contains "$output" "Syncing $TEST_SOURCE_DIR/home" "should sync home" || return 1
+}
+
+# ------------------------------------------------------------------------------
+# Test: Skips empty lines
+# ------------------------------------------------------------------------------
+test_skips_empty_lines() {
+ setup_test_env
+
+ create_test_config
+ create_test_excludes
+
+ # Create include file with empty lines
+ cat > "$TEST_CONFIG_DIR/include.txt" << EOF
+$TEST_SOURCE_DIR/home
+
+$TEST_SOURCE_DIR/etc
+
+EOF
+
+ local output
+ output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
+
+ teardown_test_env
+
+ # Should process both directories without errors
+ assert_contains "$output" "Syncing $TEST_SOURCE_DIR/home" "should sync home" || return 1
+ assert_contains "$output" "Syncing $TEST_SOURCE_DIR/etc" "should sync etc" || return 1
+}
+
+# ------------------------------------------------------------------------------
+# Test: Handles paths with spaces
+# ------------------------------------------------------------------------------
+test_handles_paths_with_spaces() {
+ setup_test_env
+
+ create_test_config
+ create_test_excludes
+
+ # Create a directory with spaces
+ mkdir -p "$TEST_SOURCE_DIR/path with spaces"
+ echo "test" > "$TEST_SOURCE_DIR/path with spaces/file.txt"
+
+ # Create include file with path containing spaces
+ cat > "$TEST_CONFIG_DIR/include.txt" << EOF
+$TEST_SOURCE_DIR/path with spaces
+EOF
+
+ local output
+ output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
+
+ teardown_test_env
+
+ # Should handle the path with spaces
+ assert_contains "$output" "path with spaces" "should handle spaces in path" || return 1
+ assert_not_contains "$output" "not found" "should not report path not found" || return 1
+}
+
+# ------------------------------------------------------------------------------
+# Test: Reports missing directory
+# ------------------------------------------------------------------------------
+test_reports_missing_directory() {
+ setup_test_env
+
+ create_test_config
+ create_test_excludes
+
+ # Create include file with non-existent path
+ cat > "$TEST_CONFIG_DIR/include.txt" << EOF
+/nonexistent/path/that/does/not/exist
+EOF
+
+ local output
+ output=$(sudo INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SKIP_MOUNT_CHECK=1 "$SCRIPT_PATH" dryrun manual 1 2>&1)
+ local exit_code=$?
+
+ teardown_test_env
+
+ assert_exit_code 1 "$exit_code" "should fail for missing directory" || return 1
+ assert_contains "$output" "not found" "should report directory not found" || return 1
+}
+
+# ------------------------------------------------------------------------------
+# Run tests
+# ------------------------------------------------------------------------------
+run_includes_tests() {
+ echo ""
+ echo "Running include file tests..."
+ echo "------------------------------------------------------------"
+
+ run_test "reads newline-separated paths" test_reads_newline_paths
+ run_test "skips comment lines" test_skips_comments
+ run_test "skips empty lines" test_skips_empty_lines
+ run_test "handles paths with spaces" test_handles_paths_with_spaces
+ run_test "reports missing directory" test_reports_missing_directory
+}
+
+# Run if executed directly
+if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
+ run_includes_tests
+ print_summary
+fi