File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,10 @@ def create_server(backend: AlertDatabaseBackend) -> FastAPI:
44
44
45
45
app = FastAPI ()
46
46
47
+ @app .get ("/v1/health" )
48
+ def healthcheck ():
49
+ return Response (content = b"OK" )
50
+
47
51
@app .get ("/v1/schemas/{schema_id}" )
48
52
def get_schema (schema_id : str ):
49
53
try :
Original file line number Diff line number Diff line change @@ -106,6 +106,11 @@ def test_get_missing_schema(self):
106
106
response = self ._get_schema ("bogus" )
107
107
self .assertEqual (response .status_code , 404 )
108
108
109
+ def test_healthcheck (self ):
110
+ """Test that the healthcheck endpoint returns 200."""
111
+ response = self .client .get ("/v1/health" )
112
+ self .assertEqual (response .status_code , 200 )
113
+
109
114
def _get_alert (self , alert_id : str ) -> requests .Response :
110
115
return self .client .get (f"/v1/alerts/{ alert_id } " )
111
116
Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from fastapi .testclient import TestClient
3
+
4
+ from alertdb .server import create_server
5
+ from alertdb .storage import FileBackend
6
+
7
+
8
+ @pytest .fixture
9
+ def file_backend (tmp_path ):
10
+ """Pytest fixture for a file-based backend"""
11
+ yield FileBackend (str (tmp_path ))
12
+
13
+
14
+ def test_server_healthcheck (file_backend ):
15
+ """Test that the server responds on the healthcheck endpoint."""
16
+ server = create_server (file_backend )
17
+ client = TestClient (server )
18
+ response = client .get ("/v1/health" )
19
+ assert response .status_code == 200
You can’t perform that action at this time.
0 commit comments