xiangqinxiaochengxu/backend/app/scripts/smoke_test.py
2026-05-16 19:01:44 +08:00

42 lines
1.1 KiB
Python

from __future__ import annotations
import asyncio
import os
from typing import Any
import httpx
BASE_URL = os.getenv("BASE_URL", "https://ghxiangqin.com/api/v1")
async def fetch(client: httpx.AsyncClient, path: str) -> tuple[int, Any]:
res = await client.get(path)
try:
body = res.json()
except Exception:
body = res.text
return res.status_code, body
async def main() -> int:
async with httpx.AsyncClient(base_url=BASE_URL, timeout=10.0) as client:
checks = [
("/health", "health"),
("/auth/public-config", "public-config"),
("/announcements?page_size=1", "announcements"),
("/activities?page_size=1", "activities"),
]
failed = False
for path, name in checks:
status_code, body = await fetch(client, path)
ok = status_code == 200
print(f"{name}: {'OK' if ok else 'FAIL'} {status_code} {body}")
failed = failed or not ok
return 1 if failed else 0
if __name__ == "__main__":
raise SystemExit(asyncio.run(main()))