#!/usr/bin/env bash # End-to-end test: starts the Rust server and runs the API smoke test against it. # # Usage: bash scripts/e2e-test.sh (requires a built backend: cargo build in backend/) set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" PORT="${PORT:-3100}" BASE_URL="http://127.0.0.1:${PORT}" STORAGE="$(mktemp -d)" SERVER_PID="" cleanup() { if [[ -n "${SERVER_PID}" ]]; then kill "${SERVER_PID}" 2>/dev/null || true fi rm -rf "${STORAGE}" } trap cleanup EXIT if [[ ! -x "${ROOT}/backend/target/debug/filehost" ]]; then echo "backend binary not found; run 'cargo build' in backend/ first" >&2 exit 1 fi STORAGE_DIR="${STORAGE}" STATIC_DIR="${ROOT}/frontend/dist" PORT="${PORT}" \ "${ROOT}/backend/target/debug/filehost" & SERVER_PID=$! # Wait for readiness. for _ in $(seq 1 50); do if curl -sS -f "${BASE_URL}/api/health" >/dev/null 2>&1; then break fi sleep 0.1 done # Static frontend checks. INDEX_CT="$(curl -sS -o /dev/null -w '%{content_type}' "${BASE_URL}/")" LOGO_CODE="$(curl -sS -o /dev/null -w '%{http_code}' "${BASE_URL}/logo.svg")" FAVICON_CODE="$(curl -sS -o /dev/null -w '%{http_code}' "${BASE_URL}/favicon.svg")" echo "static / -> ${INDEX_CT}" echo "static /logo.svg -> ${LOGO_CODE}" echo "static /favicon.svg -> ${FAVICON_CODE}" if [[ "${INDEX_CT}" != text/html* ]]; then echo "FAIL: static / did not return HTML (got '${INDEX_CT}')" >&2 exit 1 fi if [[ "${LOGO_CODE}" != "200" ]]; then echo "FAIL: static /logo.svg returned ${LOGO_CODE}" >&2 exit 1 fi if [[ "${FAVICON_CODE}" != "200" ]]; then echo "FAIL: static /favicon.svg returned ${FAVICON_CODE}" >&2 exit 1 fi echo "running smoke test against ${BASE_URL}" BASE_URL="${BASE_URL}" bash "${ROOT}/scripts/smoke-test.sh"