From d3467b357fb96e6fa758ca2e746cd3125e44b9c6 Mon Sep 17 00:00:00 2001 From: Julian Haseleu Date: Thu, 9 Oct 2025 14:44:43 +0000 Subject: [PATCH] fix test - ensures the server is listening before the test --- internal/health_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/health_test.go b/internal/health_test.go index 01667b4..6913e3c 100644 --- a/internal/health_test.go +++ b/internal/health_test.go @@ -4,6 +4,7 @@ import ( "net/http" "strings" "testing" + "time" ) func TestHealth(t *testing.T) { @@ -11,14 +12,19 @@ func TestHealth(t *testing.T) { go func() { hs.Start() }() + + // Give the server time to start up + time.Sleep(100 * time.Millisecond) + request, _ := http.NewRequest(http.MethodGet, "http://localhost:8080/health", strings.NewReader("")) resp, err := http.DefaultClient.Do(request) if err != nil { t.Errorf("Health endpoint did not start: %v", err) + return } - if resp.StatusCode != http.StatusOK { + if resp != nil && resp.StatusCode != http.StatusOK { t.Errorf("Bad response from health endpoint. Want: %d, got %d", http.StatusOK, resp.StatusCode) } }