feat(server): add /api/healthz endpoint with rich health info

Adds a Kubernetes-style healthz endpoint returning status, version,
uptime_seconds and timestamp. Non-breaking — /api/health is preserved.

- New route: GET /api/healthz
- New handler: handleHealthz with HealthzResponse struct
- New unit test: pkg/server/healthz_test.go (passes locally)
- New BDD scenario: features/health/health.feature
- BDD steps: pkg/bdd/steps/health_steps.go, common_steps.go

Note: BDD tests require Postgres and will be validated by CI.

🤖 Co-Authored-By: Mistral Vibe (devstral-2 / mistral-medium-3.5)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-03 12:25:24 +02:00
parent 8503d0824e
commit 4bbf68ebea
6 changed files with 128 additions and 1 deletions

View File

@@ -0,0 +1,43 @@
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)
}