warpgate/tests/07-network/test-offline-cached-reads.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

75 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Test: all cached files remain readable while fully offline
#
# Creates 3 test files (100 KB each) on the NAS, reads them through the
# FUSE mount to warm the cache, severs the network, and reads all three
# again. Every read should succeed from the local VFS cache and the
# content should match the originals.
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
# --- Arrange ---
start_mock_nas
nas_create_file "alpha.dat" 100
nas_create_file "bravo.dat" 100
nas_create_file "charlie.dat" 100
# Record NAS-side checksums
cksum_alpha=$(nas_file_checksum "alpha.dat")
cksum_bravo=$(nas_file_checksum "bravo.dat")
cksum_charlie=$(nas_file_checksum "charlie.dat")
gen_config
start_warpgate
wait_for_mount
wait_for_rc_api
# --- Warm the cache by reading each file ---
cat "$TEST_MOUNT/alpha.dat" > /dev/null
cat "$TEST_MOUNT/bravo.dat" > /dev/null
cat "$TEST_MOUNT/charlie.dat" > /dev/null
assert_cached "alpha.dat"
assert_cached "bravo.dat"
assert_cached "charlie.dat"
# --- Act: go offline ---
inject_network_down
# Read all three files again from cache
actual_alpha=$(md5sum "$TEST_MOUNT/alpha.dat" | awk '{print $1}')
actual_bravo=$(md5sum "$TEST_MOUNT/bravo.dat" | awk '{print $1}')
actual_charlie=$(md5sum "$TEST_MOUNT/charlie.dat" | awk '{print $1}')
# --- Assert ---
fail=0
if [[ "$actual_alpha" != "$cksum_alpha" ]]; then
echo "FAIL: alpha.dat checksum mismatch offline" >&2
fail=1
fi
if [[ "$actual_bravo" != "$cksum_bravo" ]]; then
echo "FAIL: bravo.dat checksum mismatch offline" >&2
fail=1
fi
if [[ "$actual_charlie" != "$cksum_charlie" ]]; then
echo "FAIL: charlie.dat checksum mismatch offline" >&2
fail=1
fi
# Restore network for clean teardown
inject_network_up
if [[ "$fail" -ne 0 ]]; then
exit 1
fi
echo "PASS: $(basename "$0" .sh)"