#!/usr/bin/env bash # ============================================================================== # Unit Tests for Internal Functions (is_mounted, derive_paths) # ============================================================================== # These source the script with RSYNCSHOT_SOURCE_ONLY=1 so the functions are # defined without running the main flow, then exercise them directly. Each test # runs the source + assertions in a subshell so the derived globals and config # variables don't leak into other suites. source "$(dirname "${BASH_SOURCE[0]}")/../lib/test_helpers.sh" # ------------------------------------------------------------------------------ # is_mounted: exact mount point matches # ------------------------------------------------------------------------------ test_is_mounted_exact_match() { setup_test_env local mounts="$TEST_DIR/mounts" cat > "$mounts" < "$mounts" < "$mounts" ( INSTALLHOME="$TEST_CONFIG_DIR" RSYNCSHOT_SOURCE_ONLY=1 source "$SCRIPT_PATH" is_mounted "/media/my backup" "$mounts" ) local rc=$? teardown_test_env assert_exit_code 0 "$rc" "mount point with spaces should match" || return 1 } # ------------------------------------------------------------------------------ # is_mounted: target is treated literally, not as a regex # ------------------------------------------------------------------------------ test_is_mounted_target_is_literal() { setup_test_env local mounts="$TEST_DIR/mounts" cat > "$mounts" < "$TEST_CONFIG_DIR/config" < "$TEST_CONFIG_DIR/config" <