61 lines
3.0 KiB
Bash
Executable File
61 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
# Full system verification: build -> start simulator+api on ephemeral ports -> seed -> tests
|
|
|
|
echo "--- 1. Environment Cleanup ---"
|
|
rm -rf data/*.db* src/ModPulse.Api/data/*.db* 2>/dev/null || true
|
|
rm -f sim.log api.log unit_tests.log uat_tests.log e2e_tests.log
|
|
|
|
echo "--- 2. Build ---"
|
|
dotnet restore ModPulse.sln --nologo
|
|
dotnet build ModPulse.sln -c Release --no-restore --nologo /p:RunAnalyzersDuringBuild=false /p:DebugSymbols=false /p:DebugType=None
|
|
|
|
find_free_port() {
|
|
python3 -c 'import socket;s=socket.socket();s.bind(("",0));print(s.getsockname()[1]);s.close()' 2>/dev/null || echo 10502
|
|
}
|
|
SIM_PORT=$(find_free_port)
|
|
SIM_API_PORT=$(find_free_port)
|
|
API_PORT=$(find_free_port)
|
|
|
|
echo "--- 3. Component Startup (SIM $SIM_PORT/$SIM_API_PORT API $API_PORT) ---"
|
|
ASPNETCORE_URLS="http://localhost:${SIM_API_PORT}" Simulator__Port=${SIM_PORT} dotnet src/ModPulse.Simulator/bin/Release/net10.0/ModPulse.Simulator.dll > sim.log 2>&1 &
|
|
SIM_PID=$!
|
|
DataDirectory=./data ASPNETCORE_URLS="http://localhost:${API_PORT}" MODPULSE_API_KEY=test-key-123 dotnet src/ModPulse.Api/bin/Release/net10.0/ModPulse.Api.dll > api.log 2>&1 &
|
|
API_PID=$!
|
|
|
|
cleanup() { echo "Stopping..."; kill $SIM_PID $API_PID 2>/dev/null || true; wait $SIM_PID 2>/dev/null || true; wait $API_PID 2>/dev/null || true; }
|
|
trap cleanup EXIT INT TERM
|
|
|
|
API_HEALTH_CHECK_URL="http://localhost:${API_PORT}/health"
|
|
TIMEOUT_SECONDS=60
|
|
API_READY=false
|
|
for i in $(seq 1 $((TIMEOUT_SECONDS / 3))); do
|
|
if curl -fsS "$API_HEALTH_CHECK_URL" >/dev/null 2>&1; then
|
|
API_READY=true; echo "API is UP!"; break;
|
|
fi
|
|
echo "Waiting for API... ($((i*3))s / ${TIMEOUT_SECONDS}s)"
|
|
sleep 3
|
|
done
|
|
if [ "$API_READY" = "false" ]; then echo "ERROR: API not healthy"; cat api.log; exit 1; fi
|
|
|
|
echo "--- 4. UAT Data Seeding ---"
|
|
MODPULSE_API_URL="http://localhost:${API_PORT}" SIMULATOR_ENDPOINT="localhost:${SIM_PORT}" bash seed_uat_data.sh || { echo "Seeding failed"; exit 1; }
|
|
|
|
echo "--- 5. Test Execution ---"
|
|
echo "Running Unit Tests..."
|
|
SIMULATOR_PORT=$SIM_PORT SIMULATOR_API_PORT=$SIM_API_PORT dotnet test tests/ModPulse.Tests.csproj -c Release --no-build --nologo --logger "trx;LogFileName=unit.trx" > unit_tests.log 2>&1 || { echo "Unit tests failed"; cat unit_tests.log; exit 1; }
|
|
echo "Unit tests passed."
|
|
|
|
echo "Running Backend UAT Tests..."
|
|
SIMULATOR_PORT=$SIM_PORT SIMULATOR_API_PORT=$SIM_API_PORT RUN_UAT=true RUN_INTEGRATION_TESTS=true dotnet test tests/ModPulse.Tests.csproj -c Release --no-build --filter "Category=UAT" --nologo > uat_tests.log 2>&1 || { echo "Backend UAT failed"; cat uat_tests.log; exit 1; }
|
|
echo "Backend UAT passed."
|
|
|
|
echo "Running E2E UI Tests..."
|
|
BASE_URL="http://localhost:${API_PORT}" npx playwright test uat/02-modpulse-e2e.spec.js --project=chromium > e2e_tests.log 2>&1 || { echo "E2E failed"; cat e2e_tests.log; exit 1; }
|
|
echo "E2E passed."
|
|
|
|
echo "--- 6. Log Aggregation ---"
|
|
echo "Simulator (tail):"; tail -n 20 sim.log || true
|
|
echo "API (tail):"; tail -n 20 api.log || true
|
|
echo "--- Verification Completed Successfully ---"
|