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>
205 lines
5.8 KiB
Bash
Executable File
205 lines
5.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Warpgate Integration Test — Config Generator
|
|
#
|
|
# Generates a config.toml pointing at the mock NAS for testing.
|
|
# Supports override parameters as key=value arguments.
|
|
#
|
|
# Usage:
|
|
# source config-gen.sh
|
|
# _gen_config # defaults
|
|
# _gen_config cache.max_size=10M # override one field
|
|
# _gen_config writeback.write_back=0s # instant write-back
|
|
|
|
set -euo pipefail
|
|
|
|
_gen_config() {
|
|
local config_file="${TEST_CONFIG:-$TEST_DIR/config.toml}"
|
|
|
|
# Defaults pointing at mock NAS
|
|
local nas_host="${MOCK_NAS_IP:-10.99.0.2}"
|
|
local nas_user="root"
|
|
local nas_key_file="${TEST_SSH_KEY:-$TEST_DIR/test_key}"
|
|
local remote_path="/"
|
|
local sftp_port="22"
|
|
local sftp_connections="4"
|
|
|
|
local cache_dir="${CACHE_DIR:-$TEST_DIR/cache}"
|
|
local cache_max_size="200G"
|
|
local cache_max_age="720h"
|
|
local cache_min_free="1G"
|
|
|
|
local read_chunk_size="16M"
|
|
local read_chunk_limit="64M"
|
|
local read_ahead="32M"
|
|
local buffer_size="16M"
|
|
|
|
local bw_limit_up="0"
|
|
local bw_limit_down="0"
|
|
local bw_adaptive="true"
|
|
|
|
local write_back="5s"
|
|
local transfers="4"
|
|
|
|
local dir_cache_time="5s"
|
|
|
|
local enable_smb="true"
|
|
local enable_nfs="false"
|
|
local enable_webdav="false"
|
|
local nfs_allowed_network="10.99.0.0/24"
|
|
local webdav_port="8080"
|
|
|
|
local mount_point="${TEST_MOUNT:-$TEST_DIR/mnt}"
|
|
|
|
local warmup_auto="false"
|
|
local warmup_rules=""
|
|
|
|
# Apply overrides
|
|
for override in "$@"; do
|
|
local key="${override%%=*}"
|
|
local value="${override#*=}"
|
|
|
|
case "$key" in
|
|
connection.nas_host|nas_host) nas_host="$value" ;;
|
|
connection.nas_user|nas_user) nas_user="$value" ;;
|
|
connection.nas_key_file|nas_key_file) nas_key_file="$value" ;;
|
|
connection.remote_path|remote_path) remote_path="$value" ;;
|
|
connection.sftp_port|sftp_port) sftp_port="$value" ;;
|
|
connection.sftp_connections|sftp_connections) sftp_connections="$value" ;;
|
|
cache.dir|cache_dir) cache_dir="$value" ;;
|
|
cache.max_size|cache_max_size) cache_max_size="$value" ;;
|
|
cache.max_age|cache_max_age) cache_max_age="$value" ;;
|
|
cache.min_free|cache_min_free) cache_min_free="$value" ;;
|
|
read.chunk_size|read_chunk_size) read_chunk_size="$value" ;;
|
|
read.chunk_limit|read_chunk_limit) read_chunk_limit="$value" ;;
|
|
read.read_ahead|read_ahead) read_ahead="$value" ;;
|
|
read.buffer_size|buffer_size) buffer_size="$value" ;;
|
|
bandwidth.limit_up|bw_limit_up) bw_limit_up="$value" ;;
|
|
bandwidth.limit_down|bw_limit_down) bw_limit_down="$value" ;;
|
|
bandwidth.adaptive|bw_adaptive) bw_adaptive="$value" ;;
|
|
writeback.write_back|write_back) write_back="$value" ;;
|
|
writeback.transfers|transfers) transfers="$value" ;;
|
|
directory_cache.cache_time|dir_cache_time) dir_cache_time="$value" ;;
|
|
protocols.enable_smb|enable_smb) enable_smb="$value" ;;
|
|
protocols.enable_nfs|enable_nfs) enable_nfs="$value" ;;
|
|
protocols.enable_webdav|enable_webdav) enable_webdav="$value" ;;
|
|
protocols.nfs_allowed_network|nfs_allowed_network) nfs_allowed_network="$value" ;;
|
|
protocols.webdav_port|webdav_port) webdav_port="$value" ;;
|
|
mount.point|mount_point) mount_point="$value" ;;
|
|
warmup.auto|warmup_auto) warmup_auto="$value" ;;
|
|
warmup.rules) warmup_rules="$value" ;;
|
|
*) echo "WARNING: unknown config override: $key" >&2 ;;
|
|
esac
|
|
done
|
|
|
|
cat > "$config_file" <<CONFIG_EOF
|
|
[connection]
|
|
nas_host = "$nas_host"
|
|
nas_user = "$nas_user"
|
|
nas_key_file = "$nas_key_file"
|
|
remote_path = "$remote_path"
|
|
sftp_port = $sftp_port
|
|
sftp_connections = $sftp_connections
|
|
|
|
[cache]
|
|
dir = "$cache_dir"
|
|
max_size = "$cache_max_size"
|
|
max_age = "$cache_max_age"
|
|
min_free = "$cache_min_free"
|
|
|
|
[read]
|
|
chunk_size = "$read_chunk_size"
|
|
chunk_limit = "$read_chunk_limit"
|
|
read_ahead = "$read_ahead"
|
|
buffer_size = "$buffer_size"
|
|
|
|
[bandwidth]
|
|
limit_up = "$bw_limit_up"
|
|
limit_down = "$bw_limit_down"
|
|
adaptive = $bw_adaptive
|
|
|
|
[writeback]
|
|
write_back = "$write_back"
|
|
transfers = $transfers
|
|
|
|
[directory_cache]
|
|
cache_time = "$dir_cache_time"
|
|
|
|
[protocols]
|
|
enable_smb = $enable_smb
|
|
enable_nfs = $enable_nfs
|
|
enable_webdav = $enable_webdav
|
|
nfs_allowed_network = "$nfs_allowed_network"
|
|
webdav_port = $webdav_port
|
|
|
|
[mount]
|
|
point = "$mount_point"
|
|
|
|
[warmup]
|
|
auto = $warmup_auto
|
|
CONFIG_EOF
|
|
|
|
# Append warmup rules if specified
|
|
if [[ -n "$warmup_rules" ]]; then
|
|
echo "" >> "$config_file"
|
|
echo "$warmup_rules" >> "$config_file"
|
|
fi
|
|
|
|
export TEST_CONFIG="$config_file"
|
|
}
|
|
|
|
# Generate a minimal config (only required fields)
|
|
_gen_minimal_config() {
|
|
local config_file="${TEST_CONFIG:-$TEST_DIR/config.toml}"
|
|
|
|
cat > "$config_file" <<CONFIG_EOF
|
|
[connection]
|
|
nas_host = "${MOCK_NAS_IP:-10.99.0.2}"
|
|
nas_user = "root"
|
|
nas_key_file = "${TEST_SSH_KEY:-$TEST_DIR/test_key}"
|
|
remote_path = "/"
|
|
|
|
[cache]
|
|
dir = "${CACHE_DIR:-$TEST_DIR/cache}"
|
|
|
|
[mount]
|
|
point = "${TEST_MOUNT:-$TEST_DIR/mnt}"
|
|
CONFIG_EOF
|
|
|
|
export TEST_CONFIG="$config_file"
|
|
}
|
|
|
|
# Generate an intentionally broken config
|
|
_gen_broken_config() {
|
|
local config_file="${TEST_CONFIG:-$TEST_DIR/config.toml}"
|
|
local type="${1:-missing_field}"
|
|
|
|
case "$type" in
|
|
missing_field)
|
|
# Missing nas_host
|
|
cat > "$config_file" <<CONFIG_EOF
|
|
[connection]
|
|
nas_user = "root"
|
|
remote_path = "/"
|
|
|
|
[cache]
|
|
dir = "/tmp/cache"
|
|
|
|
[mount]
|
|
point = "/tmp/mnt"
|
|
CONFIG_EOF
|
|
;;
|
|
bad_toml)
|
|
cat > "$config_file" <<CONFIG_EOF
|
|
[connection
|
|
nas_host = "broken toml
|
|
CONFIG_EOF
|
|
;;
|
|
*)
|
|
echo "Unknown broken config type: $type" >&2
|
|
return 1
|
|
;;
|
|
esac
|
|
|
|
export TEST_CONFIG="$config_file"
|
|
}
|