OSVauco/scripts/smoke-test.sh
Chris Christiansen 9fcb9c354a
Some checks are pending
Check Python Version Consistency / Check Python Version (push) Waiting to run
feat(core): Fresh initialization - Deploy v3.6.1 Singularity Architecture
2026-09-03 04:03:09 +00:00

92 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# smoke-test.sh — OSVauco OPAX røyktest
# Kjør fra Cloud Shell etter deploy:
# bash scripts/smoke-test.sh
#
# Forutsetning: gcloud-innlogget med tilgang til prosjektet.
set -euo pipefail
URL="${OPAX_URL:-https://osvauco-agent-zjbqp3prqq-uc.a.run.app}"
# Hent token fra metadata-server (Cloud Build / VM) med riktig audience
# Fallback til gcloud ved lokal kjøring
TOKEN=$(curl -sf -H "Metadata-Flavor: Google" \
"http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/identity?audience=${URL}&format=full" 2>/dev/null) \
|| TOKEN=$(gcloud auth print-identity-token 2>/dev/null) \
|| { echo "❌ Kunne ikke hente identity token"; exit 1; }
H_AUTH="Authorization: Bearer $TOKEN"
H_JSON="Content-Type: application/json"
PASS=0
FAIL=0
check() {
local label="$1"
local expected_http="$2"
local body="$3"
local endpoint="$4"
http_code=$(curl -s -o /tmp/smoke_resp.json -w "%{http_code}" \
-X POST \
-H "$H_AUTH" \
-H "$H_JSON" \
-d "$body" \
"${URL}${endpoint}")
resp=$(cat /tmp/smoke_resp.json)
if [[ "$http_code" == "$expected_http" ]]; then
echo "✅ [$http_code] $label"
echo "$(echo "$resp" | head -c 120)"
PASS=$((PASS+1))
else
echo "❌ [$http_code] $label (forventet $expected_http)"
echo "$resp"
FAIL=$((FAIL+1))
fi
}
check_get() {
local label="$1"
local expected_http="$2"
local endpoint="$3"
http_code=$(curl -s -o /tmp/smoke_resp.json -w "%{http_code}" \
-H "$H_AUTH" \
"${URL}${endpoint}")
resp=$(cat /tmp/smoke_resp.json)
if [[ "$http_code" == "$expected_http" ]]; then
echo "✅ [$http_code] $label"
echo "$(echo "$resp" | head -c 120)"
PASS=$((PASS+1))
else
echo "❌ [$http_code] $label (forventet $expected_http)"
echo "$resp"
FAIL=$((FAIL+1))
fi
}
echo "======================================"
echo " OSVauco OPAX RØYKTEST"
echo " URL: $URL"
echo "======================================"
echo ""
# 1. Health
check_get "GET /health" 200 "/health"
# 2. /run basis
check "POST /run" 200 \
'{"message": "Hva er OPAX?", "user_id": "opax", "session_id": "smoke-test"}' "/run"
echo ""
echo "======================================"
echo " RESULTAT: ✅ $PASS bestod | ❌ $FAIL feilet"
echo "======================================"
[[ $FAIL -eq 0 ]] && exit 0 || exit 1