warpgate/tests/01-config/test-config-init-no-overwrite.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

28 lines
808 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/../harness/helpers.sh"
setup_test_env
trap teardown_test_env EXIT
TARGET="$TEST_DIR/existing.toml"
# Pre-create a file at the target path so config-init would overwrite it.
echo "# pre-existing config" > "$TARGET"
# config-init should refuse to overwrite an existing file.
output=$("$WARPGATE_BIN" config-init --output "$TARGET" 2>&1) && {
echo "FAIL: config-init should have exited non-zero for existing file"
echo " output: $output"
exit 1
}
# The error message must mention that the file already exists.
assert_output_contains "$output" "already exists"
# The original file should be untouched.
assert_file_content "$TARGET" "# pre-existing config"
echo "PASS: $(basename "$0" .sh)"