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)
	}
}
