#!/usr/bin/env bash # ============================================================================= # test-caddyfile-routing.sh — Unit test for Caddyfile routing block shape # # Verifies that the edge.hcl Nomad job template contains correctly configured # routing blocks for all subpaths: # - /forge/ — Forgejo subpath # - /ci/ — Woodpecker subpath # - /staging/ — Staging subpath # - /chat/ — Chat subpath with forward_auth # # Usage: # test-caddyfile-routing.sh [--template PATH] # # Environment variables: # EDGE_TEMPLATE — Path to edge.hcl template (default: nomad/jobs/edge.hcl) # # Exit codes: # 0 — All checks passed # 1 — One or more checks failed # ============================================================================= set -euo pipefail # Script directory for relative paths SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="${SCRIPT_DIR}/.." # Configuration EDGE_TEMPLATE="${EDGE_TEMPLATE:-${PROJECT_ROOT}/nomad/jobs/edge.hcl}" # Track test status FAILED=0 PASSED=0 # ───────────────────────────────────────────────────────────────────────────── # Logging helpers # ───────────────────────────────────────────────────────────────────────────── log_info() { echo "[INFO] $*" } log_pass() { echo "[PASS] $*" ((PASSED++)) || true } log_fail() { echo "[FAIL] $*" ((FAILED++)) || true } log_section() { echo "" echo "=== $* ===" echo "" } # ───────────────────────────────────────────────────────────────────────────── # Test helpers # ───────────────────────────────────────────────────────────────────────────── # Extract the Caddyfile template from edge.hcl # The template is embedded in a Nomad template stanza with <