#!/usr/bin/env bash # Test: `warpgate preset ` applies correct values to config file. # # Verifies that each preset writes the expected cache.max_size to the config, # that CLI and API presets are unified (same source of truth), and that the # command exits 0 for valid presets and non-zero for unknown ones. # # Does NOT require a running warpgate daemon — only needs a config file. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" source "$SCRIPT_DIR/../harness/helpers.sh" setup_test_env trap teardown_test_env EXIT # Generate a minimal config pointing at a fake NAS (we don't connect to it) gen_config "nas_host=127.0.0.1" # ── photographer preset ────────────────────────────────────────────────────── output=$("$WARPGATE_BIN" preset photographer -c "$TEST_CONFIG" 2>&1) || { echo "FAIL: 'warpgate preset photographer' exited non-zero" echo " output: $output" exit 1 } assert_output_contains "$output" "photographer" # Verify cache.max_size was written as 500G if ! grep -q 'max_size = "500G"' "$TEST_CONFIG"; then echo "FAIL: photographer preset did not write cache.max_size = \"500G\"" echo " config: $(grep max_size "$TEST_CONFIG" || echo '(not found)')" exit 1 fi # Verify chunk_size = 256M if ! grep -q 'chunk_size = "256M"' "$TEST_CONFIG"; then echo "FAIL: photographer preset did not write chunk_size = \"256M\"" exit 1 fi # Verify chunk_limit = 1G (field added in this round of fixes) if ! grep -q 'chunk_limit = "1G"' "$TEST_CONFIG"; then echo "FAIL: photographer preset did not write chunk_limit = \"1G\"" exit 1 fi # Verify multi_thread_streams = 4 if ! grep -q 'multi_thread_streams = 4' "$TEST_CONFIG"; then echo "FAIL: photographer preset did not write multi_thread_streams = 4" exit 1 fi # Verify webdav is disabled for photographer if grep -q 'enable_webdav = true' "$TEST_CONFIG"; then echo "FAIL: photographer preset should NOT enable WebDAV" exit 1 fi # ── video preset ───────────────────────────────────────────────────────────── gen_config "nas_host=127.0.0.1" output=$("$WARPGATE_BIN" preset video -c "$TEST_CONFIG" 2>&1) || { echo "FAIL: 'warpgate preset video' exited non-zero" echo " output: $output" exit 1 } if ! grep -q 'max_size = "1T"' "$TEST_CONFIG"; then echo "FAIL: video preset did not write cache.max_size = \"1T\"" exit 1 fi if ! grep -q 'chunk_size = "512M"' "$TEST_CONFIG"; then echo "FAIL: video preset did not write chunk_size = \"512M\"" exit 1 fi if ! grep -q 'chunk_limit = "2G"' "$TEST_CONFIG"; then echo "FAIL: video preset did not write chunk_limit = \"2G\"" exit 1 fi if ! grep -q 'multi_thread_streams = 2' "$TEST_CONFIG"; then echo "FAIL: video preset did not write multi_thread_streams = 2" exit 1 fi # ── office preset ───────────────────────────────────────────────────────────── gen_config "nas_host=127.0.0.1" output=$("$WARPGATE_BIN" preset office -c "$TEST_CONFIG" 2>&1) || { echo "FAIL: 'warpgate preset office' exited non-zero" echo " output: $output" exit 1 } if ! grep -q 'max_size = "50G"' "$TEST_CONFIG"; then echo "FAIL: office preset did not write cache.max_size = \"50G\"" exit 1 fi # office buffer_size must be 128M (not 64M — unified in Step 1 fix) if ! grep -q 'buffer_size = "128M"' "$TEST_CONFIG"; then echo "FAIL: office preset should write buffer_size = \"128M\", got:" grep buffer_size "$TEST_CONFIG" || echo " (not found)" exit 1 fi # office should enable WebDAV if ! grep -q 'enable_webdav = true' "$TEST_CONFIG"; then echo "FAIL: office preset should enable WebDAV" exit 1 fi # office write_back should be 5s (unified; was incorrectly 3s in API before fix) if ! grep -q 'write_back = "5s"' "$TEST_CONFIG"; then echo "FAIL: office preset should write write_back = \"5s\"" exit 1 fi # ── unknown preset returns non-zero ────────────────────────────────────────── gen_config "nas_host=127.0.0.1" if "$WARPGATE_BIN" preset bad-preset -c "$TEST_CONFIG" 2>&1; then echo "FAIL: unknown preset should exit non-zero" exit 1 fi # ── config remains parseable after preset ───────────────────────────────────── gen_config "nas_host=127.0.0.1" "$WARPGATE_BIN" preset photographer -c "$TEST_CONFIG" > /dev/null 2>&1 # `warpgate status` parses the config; it will fail the mount check but not # the config parse — ensure it doesn't error on config parsing status_out=$("$WARPGATE_BIN" status -c "$TEST_CONFIG" 2>&1) || true if echo "$status_out" | grep -qi "failed to parse\|toml\|invalid"; then echo "FAIL: config written by preset is not parseable" echo " output: $status_out" exit 1 fi echo "PASS: $(basename "$0" .sh)"