test(health): assert healthz_failed log on 503 (#26)
This commit is contained in:
parent
d282416a34
commit
75c825924b
1 changed files with 9 additions and 1 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from sqlalchemy.exc import OperationalError
|
||||
|
||||
from quartermaster.db import get_session
|
||||
|
|
@ -13,7 +15,7 @@ def test_healthz_returns_ok(client):
|
|||
assert response.json() == {"status": "ok"}
|
||||
|
||||
|
||||
def test_healthz_returns_503_when_db_check_raises():
|
||||
def test_healthz_returns_503_when_db_check_raises(caplog):
|
||||
app = create_app()
|
||||
|
||||
def broken_session():
|
||||
|
|
@ -32,6 +34,7 @@ def test_healthz_returns_503_when_db_check_raises():
|
|||
|
||||
app.dependency_overrides[get_session] = broken_session
|
||||
|
||||
caplog.set_level(logging.WARNING, logger="quartermaster.health")
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/healthz")
|
||||
|
||||
|
|
@ -39,3 +42,8 @@ def test_healthz_returns_503_when_db_check_raises():
|
|||
body = response.json()
|
||||
assert body["status"] == "error"
|
||||
assert body["detail"] == "OperationalError"
|
||||
|
||||
failed = [r for r in caplog.records if getattr(r, "event", None) == "healthz_failed"]
|
||||
assert len(failed) == 1
|
||||
assert failed[0].levelname == "WARNING"
|
||||
assert failed[0].error_class == "OperationalError"
|
||||
|
|
|
|||
Loading…
Reference in a new issue