warpgate/tests/05-cache/test-warmup-skip-cached.sh
grabbit a2d49137f9 Add comprehensive test suite: 63 integration tests + 110 Rust unit tests
Integration tests (tests/):
- 9 categories covering config, lifecycle, signals, supervision,
  cache, writeback, network faults, crash recovery, and CLI
- Shell-based harness with mock NAS (network namespace + SFTP),
  fault injection (tc netem), and power loss simulation
- TAP format runner (run-all.sh) with proper SKIP detection

Rust unit tests (warpgate/src/):
- 110 tests across 14 modules, all passing in 0.01s
- Config parsing, defaults validation, RestartTracker logic,
  RC API response parsing, rclone arg generation, service
  config generation, CLI output formatting, warmup path logic

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-18 11:21:35 +08:00

50 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Test: warmup skips files that are already cached
#
# Verifies that running warmup a second time detects files already
# present in $CACHE_DIR/vfs/nas/... and skips re-reading them. The
# second run output should report all files as "skipped".
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 test files
start_mock_nas
nas_create_file "a.txt" 4
nas_create_file "b.txt" 4
nas_create_file "c.txt" 4
# Generate default config
gen_config
# Start warpgate and wait for readiness
start_warpgate
wait_for_mount
wait_for_rc_api
# First warmup — should cache all files
run_warpgate_cmd warmup "" > /dev/null 2>&1
# Verify all files are cached
assert_cached "a.txt"
assert_cached "b.txt"
assert_cached "c.txt"
# Second warmup — should skip all files since they are already cached
output=$(run_warpgate_cmd warmup "" 2>&1)
# Count the number of "skipped" occurrences (expect 3, one per file)
skipped_count=$(echo "$output" | grep -c "skipped" || true)
if [[ "$skipped_count" -lt 3 ]]; then
echo "FAIL: expected at least 3 files skipped, got $skipped_count" >&2
echo " warmup output: $output" >&2
exit 1
fi
echo "PASS: $(basename "$0" .sh)"