File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
packages/service-library/tests/fastapi Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ from collections .abc import AsyncIterable
2+
3+ import pytest
4+ from asgi_lifespan import LifespanManager
5+ from fastapi import FastAPI
6+ from httpx import AsyncClient
7+ from servicelib .fastapi .monitoring import setup_prometheus_instrumentation
8+
9+
10+ @pytest .fixture
11+ async def app (app : FastAPI ) -> AsyncIterable [FastAPI ]:
12+ """
13+ Fixture that sets up the Prometheus middleware in the FastAPI app.
14+ """
15+ setup_prometheus_instrumentation (app )
16+ async with LifespanManager (app ):
17+ yield app
18+
19+
20+ async def test_metrics_endpoint (client : AsyncClient , app : FastAPI ):
21+ """
22+ Test that the /metrics endpoint is available and returns Prometheus metrics.
23+ """
24+ response = await client .get ("/metrics" )
25+ assert response .status_code == 200
26+ assert "# HELP" in response .text
27+ assert "# TYPE" in response .text
You can’t perform that action at this time.
0 commit comments