Files
health/compliance_test.go
Rene Nochebuena e1b6b7ddd7 feat(health): initial stable release v0.9.0
HTTP health check handler with parallel goroutine-per-check execution, 5 s request-derived timeout, and two-level criticality (LevelCritical → 503, LevelDegraded → 200).

What's included:
- `Checkable` interface (HealthCheck / Name / Priority) and `Level` type with LevelCritical and LevelDegraded constants
- `NewHandler(logger, checks...)` returning http.Handler; runs all checks concurrently via buffered channel, returns JSON with per-component status and latency
- `ComponentStatus` and `Response` types for the JSON response body

Tested-via: todo-api POC integration
Reviewed-against: docs/adr/
2026-03-18 14:06:17 -06:00

28 lines
953 B
Go

package health_test
import (
"context"
"code.nochebuena.dev/go/health"
)
type testLogger struct{}
func (t *testLogger) Debug(msg string, args ...any) {}
func (t *testLogger) Info(msg string, args ...any) {}
func (t *testLogger) Warn(msg string, args ...any) {}
func (t *testLogger) Error(msg string, err error, args ...any) {}
func (t *testLogger) WithContext(ctx context.Context) health.Logger { return t }
// Compile-time check: testLogger satisfies health.Logger.
var _ health.Logger = (*testLogger)(nil)
type testCheck struct{}
func (t *testCheck) HealthCheck(ctx context.Context) error { return nil }
func (t *testCheck) Name() string { return "test" }
func (t *testCheck) Priority() health.Level { return health.LevelCritical }
// Compile-time check: testCheck satisfies health.Checkable.
var _ health.Checkable = (*testCheck)(nil)