l-ai-agent-kaya/internal/buildinfo/buildinfo_test.go
alex 7758c097af
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Expose stamped /healthz JSON next to Prometheus metrics.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 16:28:20 +03:00

43 lines
1021 B
Go

package buildinfo
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestHandlerOK(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/healthz", nil)
rec := httptest.NewRecorder()
Handler().ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("code=%d", rec.Code)
}
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
t.Fatalf("content-type=%q", ct)
}
var body Response
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
if body.Status != "ok" || body.Name != Name || body.Description == "" {
t.Fatalf("unexpected body: %+v", body)
}
if len(body.Tags) == 0 {
t.Fatal("expected tags")
}
if body.Build.Commit == "" {
t.Fatal("expected commit")
}
}
func TestHandlerMethodNotAllowed(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/healthz", nil)
rec := httptest.NewRecorder()
Handler().ServeHTTP(rec, req)
if rec.Code != http.StatusMethodNotAllowed {
t.Fatalf("code=%d", rec.Code)
}
}