feat(server): add /api/healthz endpoint with rich health info (#20)
Some checks failed
CI/CD Pipeline / Build Docker Cache (push) Successful in 17s
CI/CD Pipeline / CI Pipeline (push) Failing after 4m28s
CI/CD Pipeline / Trigger Docker Push (push) Has been skipped

Adds Kubernetes-style /api/healthz endpoint with status/version/uptime_seconds/timestamp.

Non-breaking — /api/health preserved. Includes unit test (passes locally) and BDD scenario (validated by CI).

Généré ~95% en autonomie par Mistral Vibe via workspace ICM ~/Work/Vibe/workspaces/healthz-feature/.

Co-authored-by: Gabriel Radureau <arcodange@gmail.com>
Co-committed-by: Gabriel Radureau <arcodange@gmail.com>
This commit was merged in pull request #20.
This commit is contained in:
2026-05-03 12:25:54 +02:00
committed by arcodange
parent 8503d0824e
commit 045823ec8e
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)
}