015 add tracing
This commit is contained in:
@@ -7,6 +7,7 @@ from fastapi import FastAPI
|
||||
from app import config as config_module
|
||||
from app.config import Settings, get_settings
|
||||
from app.runtime import logging as logging_module
|
||||
from app.runtime import tracing as tracing_module
|
||||
|
||||
TEST_CONFIG_FILE = Path(__file__).resolve().parents[2] / "config.test.yaml"
|
||||
|
||||
@@ -19,27 +20,40 @@ def _import_main_module(monkeypatch):
|
||||
|
||||
|
||||
def test_app_import_smoke(monkeypatch) -> None:
|
||||
bootstrap_calls: list[None] = []
|
||||
logging_bootstrap_calls: list[None] = []
|
||||
tracing_bootstrap_calls: list[tuple[FastAPI, object]] = []
|
||||
|
||||
def fake_configure_logging() -> None:
|
||||
bootstrap_calls.append(None)
|
||||
logging_bootstrap_calls.append(None)
|
||||
|
||||
def fake_configure_tracing(app: FastAPI, observability: object) -> None:
|
||||
tracing_bootstrap_calls.append((app, observability))
|
||||
|
||||
monkeypatch.setattr(logging_module, "configure_logging", fake_configure_logging)
|
||||
monkeypatch.setattr(tracing_module, "configure_tracing", fake_configure_tracing)
|
||||
main_module = _import_main_module(monkeypatch)
|
||||
|
||||
assert isinstance(main_module.app, FastAPI)
|
||||
assert isinstance(main_module.app.state.settings, Settings)
|
||||
assert bootstrap_calls == [None]
|
||||
assert logging_bootstrap_calls == [None]
|
||||
assert tracing_bootstrap_calls == [
|
||||
(main_module.app, main_module.app.state.settings.observability)
|
||||
]
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
def test_app_created_with_provided_settings(monkeypatch) -> None:
|
||||
bootstrap_calls: list[None] = []
|
||||
logging_bootstrap_calls: list[None] = []
|
||||
tracing_bootstrap_calls: list[tuple[FastAPI, object]] = []
|
||||
|
||||
def fake_configure_logging() -> None:
|
||||
bootstrap_calls.append(None)
|
||||
logging_bootstrap_calls.append(None)
|
||||
|
||||
def fake_configure_tracing(app: FastAPI, observability: object) -> None:
|
||||
tracing_bootstrap_calls.append((app, observability))
|
||||
|
||||
monkeypatch.setattr(logging_module, "configure_logging", fake_configure_logging)
|
||||
monkeypatch.setattr(tracing_module, "configure_tracing", fake_configure_tracing)
|
||||
main_module = _import_main_module(monkeypatch)
|
||||
monkeypatch.setattr(config_module, "TEST_CONFIG_FILE", str(TEST_CONFIG_FILE))
|
||||
|
||||
@@ -47,5 +61,9 @@ def test_app_created_with_provided_settings(monkeypatch) -> None:
|
||||
instance = main_module.create_app(settings=settings)
|
||||
|
||||
assert instance.state.settings is settings
|
||||
assert bootstrap_calls == [None, None]
|
||||
assert logging_bootstrap_calls == [None, None]
|
||||
assert tracing_bootstrap_calls == [
|
||||
(main_module.app, main_module.app.state.settings.observability),
|
||||
(instance, settings.observability),
|
||||
]
|
||||
get_settings.cache_clear()
|
||||
|
||||
Reference in New Issue
Block a user