Files
ai-gateway-go/internal/platform/health/checker_test.go
T
superidou 5759c1862e AI Gateway Go 0.10.0 源码快照 + 旗舰版需求规划报告
M0-M7 已完成:核心网关(身份/RBAC/TOTP/OIDC/SAML/Provider/配额/路由/内容策略/审计/定价)+ 资源市场(MCP/Skills/数字员工)。
含 22 个 PostgreSQL 迁移、管理端/门户端前端源码、OpenAPI 契约、部署 compose。

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-12 11:45:54 +08:00

36 lines
980 B
Go

package health
import (
"context"
"errors"
"testing"
"time"
)
func TestOptionalFailureDegradesWithoutBlockingReadiness(t *testing.T) {
checker := Checker{
Timeout: time.Second,
Dependencies: []Dependency{
{Name: "postgres", Required: true, Probe: func(context.Context) error { return nil }},
{Name: "redis_cache", Required: false, Probe: func(context.Context) error { return errors.New("offline") }},
},
}
report := checker.Readiness(context.Background())
if !report.Ready || report.Status != "degraded" {
t.Fatalf("unexpected report: %+v", report)
}
}
func TestRequiredFailureBlocksReadiness(t *testing.T) {
checker := Checker{
Timeout: time.Second,
Dependencies: []Dependency{
{Name: "postgres", Required: true, Probe: func(context.Context) error { return errors.New("offline") }},
},
}
report := checker.Readiness(context.Background())
if report.Ready || report.Status != "unavailable" {
t.Fatalf("unexpected report: %+v", report)
}
}