#!/usr/bin/env bash # Test: VFS cache stores files at the expected filesystem path # # Verifies that when a file is read through the FUSE mount, it appears # at $CACHE_DIR/vfs//FILENAME — the exact path that warmup's # is_cached logic checks to decide whether to skip a file. # The default connection name is "nas". set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/../harness/helpers.sh" source "$SCRIPT_DIR/../harness/mock-nas.sh" require_root setup_test_env trap teardown_test_env EXIT # Start mock NAS and create files at various depths start_mock_nas nas_create_file_content "root-file.txt" "root-level" nas_create_file_content "sub/nested-file.txt" "nested" nas_create_file_content "sub/deep/deep-file.txt" "deep-nested" # Generate default config (remote_path="/") gen_config # Start warpgate and wait for readiness start_warpgate wait_for_mount wait_for_rc_api # Read each file through the FUSE mount to trigger caching cat "$TEST_MOUNT/root-file.txt" > /dev/null cat "$TEST_MOUNT/sub/nested-file.txt" > /dev/null cat "$TEST_MOUNT/sub/deep/deep-file.txt" > /dev/null # Verify that each file is cached at the expected path under # $CACHE_DIR/vfs/nas/ (since remote_path="/", no extra prefix) assert_cached "root-file.txt" assert_cached "sub/nested-file.txt" assert_cached "sub/deep/deep-file.txt" # Also verify the actual on-disk paths exist and have correct content assert_file_content "$CACHE_DIR/vfs/nas/root-file.txt" "root-level" assert_file_content "$CACHE_DIR/vfs/nas/sub/nested-file.txt" "nested" assert_file_content "$CACHE_DIR/vfs/nas/sub/deep/deep-file.txt" "deep-nested" # Test that assert_cached works on files placed directly into the cache # directory (bypassing FUSE). This validates the cache path detection used # by warmup's is_cached logic. mkdir -p "$CACHE_DIR/vfs/nas" echo -n "manually-placed" > "$CACHE_DIR/vfs/nas/manual-file.txt" assert_cached "manual-file.txt" echo "PASS: $(basename "$0" .sh)"