feat(api): add composite ogen handler for incremental operations
This commit is contained in:
1 parent
0f206bfc29
commit
b2f6e87bfe
6 files changed
+133
-6
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"lincodex/backend/internal/adapter/primary/http/api"
|
||||
v1 "lincodex/backend/internal/adapter/primary/http/v1"
|
||||
metrics "lincodex/backend/internal/adapter/secondary/prometheus"
|
||||
"lincodex/backend/internal/usecase/health"
|
||||
@@ -70,11 +71,33 @@ func TestPublicHealthRouteUsesGeneratedOgenHandler(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// An operation without a business implementation must answer 501 through the
|
||||
// router instead of a successful stub or a generic 500. GetHealthz served by
|
||||
// api.UnimplementedHandler stands in for any such operation, so the check needs
|
||||
// no extra contract operation.
|
||||
func TestPublicUnimplementedOperationReturnsNotImplemented(t *testing.T) {
|
||||
healthHandler := newTestHealthHandler(func(context.Context) error { return nil })
|
||||
router := newTestRouterWithAPI(t, healthHandler, api.UnimplementedHandler{})
|
||||
response := httptest.NewRecorder()
|
||||
router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/api/v1/healthz", nil))
|
||||
if response.Code != http.StatusNotImplemented {
|
||||
t.Fatalf("status code = %d, want %d: %s", response.Code, http.StatusNotImplemented, response.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func newTestRouter(t *testing.T, checker readinessFunc) http.Handler {
|
||||
t.Helper()
|
||||
readiness := health.NewReadiness(checker)
|
||||
healthHandler := v1.NewHealthHandler(readiness, time.Second)
|
||||
router, err := NewRouter(healthHandler, metrics.New(), slog.New(slog.DiscardHandler))
|
||||
healthHandler := newTestHealthHandler(checker)
|
||||
return newTestRouterWithAPI(t, healthHandler, v1.NewHandler(healthHandler))
|
||||
}
|
||||
|
||||
func newTestHealthHandler(checker readinessFunc) *v1.HealthHandler {
|
||||
return v1.NewHealthHandler(health.NewReadiness(checker), time.Second)
|
||||
}
|
||||
|
||||
func newTestRouterWithAPI(t *testing.T, healthHandler *v1.HealthHandler, apiHandler api.Handler) http.Handler {
|
||||
t.Helper()
|
||||
router, err := NewRouter(healthHandler, apiHandler, metrics.New(), slog.New(slog.DiscardHandler))
|
||||
if err != nil {
|
||||
t.Fatalf("NewRouter() error = %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user