@@ -166,3 +166,44 @@ func TestServer_Start(t *testing.T) {
166166 t .Fatal ("Server did not shut down within timeout period" )
167167 }
168168}
169+
170+ func TestServer_HealthEndpoint (t * testing.T ) {
171+ cfg := getDefaultConfig ()
172+ cfg .Server .Port = testutil .GetPortForTest (t )
173+
174+ registry := toolsets .NewRegistry (cfg , []toolsets.Toolset {})
175+ srv := NewServer (cfg , registry )
176+
177+ ctx , cancel := context .WithCancel (context .Background ())
178+ defer cancel ()
179+
180+ errChan := make (chan error , 1 )
181+
182+ go func () {
183+ errChan <- srv .Start (ctx )
184+ }()
185+
186+ serverURL := "http://" + net .JoinHostPort (cfg .Server .Address , strconv .Itoa (cfg .Server .Port ))
187+ err := testutil .WaitForServerReady (serverURL , 3 * time .Second )
188+ require .NoError (t , err , "Server should start within timeout" )
189+
190+ // Test health endpoint.
191+ //nolint:noctx
192+ resp , err := http .Get (serverURL + "/health" )
193+ require .NoError (t , err , "Health endpoint should be reachable" )
194+ require .NoError (t , resp .Body .Close ())
195+
196+ assert .Equal (t , http .StatusOK , resp .StatusCode , "Health endpoint should return 200 OK" )
197+ assert .Equal (t , "application/json" , resp .Header .Get ("Content-Type" ), "Health endpoint should return JSON" )
198+
199+ // Trigger shutdown.
200+ cancel ()
201+
202+ // Wait for server to shut down.
203+ select {
204+ case <- errChan :
205+ // Server shut down successfully
206+ case <- time .After (ShutdownTimeout + time .Second ):
207+ t .Fatal ("Server did not shut down within timeout period" )
208+ }
209+ }
0 commit comments