package server import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" "dance-lessons-coach/pkg/config" "github.com/stretchr/testify/assert" ) func TestHandleHealthz(t *testing.T) { // Setup cfg := &config.Config{} s := NewServer(cfg, context.Background()) // Create request req := httptest.NewRequest(http.MethodGet, "/api/healthz", nil) w := httptest.NewRecorder() // Call handler s.handleHealthz(w, req) // Check status code assert.Equal(t, http.StatusOK, w.Code) // Check content type assert.Equal(t, "application/json", w.Header().Get("Content-Type")) // Decode response var resp HealthzResponse err := json.NewDecoder(w.Body).Decode(&resp) assert.NoError(t, err) // Assert fields assert.Equal(t, "healthy", resp.Status) assert.NotEmpty(t, resp.Version) assert.GreaterOrEqual(t, resp.UptimeSeconds, int64(0)) assert.NotZero(t, resp.Timestamp) }