#!/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 # Generate a minimal config — only required fields are set. # The binary should fill in all other fields with defaults. source "$HARNESS_DIR/config-gen.sh" _gen_minimal_config # Verify the binary accepts the minimal config without complaint. # This proves that defaults are applied for every non-required field. output=$("$WARPGATE_BIN" status -c "$TEST_CONFIG" 2>&1) || { echo "FAIL: warpgate status exited non-zero; defaults should fill in" echo " output: $output" exit 1 } # The minimal config intentionally omits these fields (all should be # filled by compiled-in defaults matching the PRD): # sftp_port = 22 # sftp_connections = 8 # max_size = "200G" # max_age = "720h" # min_free = "10G" # chunk_size = "256M" # write_back = "5s" # transfers = 4 # enable_smb = true # enable_nfs = false # mount.point = "/mnt/nas-photos" # # We cannot easily extract the in-memory defaults from the binary, but a # successful status invocation on a minimal config is proof that every # default was applied without error. # Double-check the config file does NOT contain the fields that should # come from defaults — confirming we are truly testing the defaults path. assert_output_not_contains "$(cat "$TEST_CONFIG")" "sftp_port" assert_output_not_contains "$(cat "$TEST_CONFIG")" "max_size" assert_output_not_contains "$(cat "$TEST_CONFIG")" "enable_smb" assert_output_not_contains "$(cat "$TEST_CONFIG")" "transfers" # Parse the status output for actual applied defaults and verify key # values match the PRD specifications. assert_output_contains "$output" "sftp_port" assert_output_contains "$output" "22" assert_output_contains "$output" "sftp_connections" assert_output_contains "$output" "8" assert_output_contains "$output" "write_back" assert_output_contains "$output" "5s" assert_output_contains "$output" "enable_smb" assert_output_contains "$output" "true" assert_output_contains "$output" "enable_nfs" assert_output_contains "$output" "false" assert_output_contains "$output" "enable_webdav" assert_output_contains "$output" "false" assert_output_contains "$output" "dir_cache_time" assert_output_contains "$output" "5m0s" assert_output_contains "$output" "transfers" assert_output_contains "$output" "4" echo "PASS: $(basename "$0" .sh)"