#!/usr/bin/env bash # Generic smoke test for any deployed app. # # Usage: ./scripts/smoke-test.sh [base_url] # Default: https://staging.truckwash.io # # Required env vars (set by GitHub Action): # SMOKE_BASE_URL - base URL to test (default: https://staging.truckwash.io) # # Optional env vars: # SMOKE_TOKEN - bearer token for authenticated checks # SMOKE_TIMEOUT - curl timeout in seconds (default: 10) # # Exits 0 on all-pass, 1 on any failure. set -euo pipefail BASE_URL="${SMOKE_BASE_URL:-${1:-https://staging.truckwash.io}}" TIMEOUT="${SMOKE_TIMEOUT:-10}" # Color codes RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' FAIL=0 check() { local name="$1" local url="$2" local expected="${3:-200}" local method="${4:-GET}" local status status=$(curl -s -o /dev/null -w "%{http_code}" -X "$method" --max-time "$TIMEOUT" "$url" || echo "000") if [[ "$status" =~ ^($expected)$ ]] || [[ "$expected" == "2xx" && "$status" =~ ^2 ]]; then echo -e " ${GREEN}✓${NC} $name ($status) — $url" else echo -e " ${RED}✗${NC} $name (expected $expected, got $status) — $url" FAIL=1 fi } echo "Smoke test against $BASE_URL" echo " (timeout ${TIMEOUT}s per check)" echo # === Health endpoints (universal) === check "health check" "$BASE_URL/healthz" "2xx" check "ping" "$BASE_URL/api/ping" "2xx" # === Authentication (should NOT 500) === check "login page" "$BASE_URL/login" "2xx" # === Public endpoints (api repo) === check "customer list (public schema)" "$BASE_URL/api/customer" "2xx" check "kundeoprettelse form" "$BASE_URL/kundeoprettelse" "2xx" # === Public endpoints (pleno-vue) === check "self-serve program picker" "$BASE_URL/self-serve/program" "2xx" check "vehicle step" "$BASE_URL/self-serve/vehicle" "2xx" # === Custom 404 should not 500 === check "404 page" "$BASE_URL/this-route-does-not-exist" "404" # === Optional authenticated check === if [ -n "${SMOKE_TOKEN:-}" ]; then check "auth check" "$BASE_URL/api/me" "2xx" fi echo if [ "$FAIL" -eq 0 ]; then echo -e "${GREEN}✓ All smoke tests passed${NC}" exit 0 else echo -e "${RED}✗ Some smoke tests failed${NC}" exit 1 fi