This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package datasource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSourceHealthBecomesUnknownWhenStale(t *testing.T) {
|
||||
now := time.Date(2026, 8, 1, 12, 0, 0, 0, time.UTC)
|
||||
health := SourceHealth{State: HealthHealthy, ObservedAt: now.Add(-2 * time.Minute), ReceivedAt: now, Policy: FreshnessPolicy{MaxAge: time.Minute}}
|
||||
if got := health.EffectiveState(now); got != HealthUnknown {
|
||||
t.Fatalf("effective state = %q, want unknown", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCapabilitySetRejectsDuplicateVersions(t *testing.T) {
|
||||
set := CapabilitySet{{ID: "inventory", Version: "v1", State: CapabilityEnabled}, {ID: "inventory", Version: "v1", State: CapabilityUnavailable}}
|
||||
if err := set.Validate(); err == nil {
|
||||
t.Fatal("expected duplicate capability validation error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceRejectsUnknownContractAndUnboundedHealth(t *testing.T) {
|
||||
now := time.Date(2026, 8, 1, 12, 0, 0, 0, time.UTC)
|
||||
source := Source{ID: "source-1", Name: "Prometheus", Type: SourcePrometheus, Enabled: true, Contract: "v2", Health: SourceHealth{State: HealthUnknown, ReceivedAt: now, Policy: FreshnessPolicy{MaxAge: 25 * time.Hour}}}
|
||||
if err := source.Validate(now); err == nil {
|
||||
t.Fatal("expected source validation error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdapterContractIsTransportFree(t *testing.T) {
|
||||
var adapter Adapter = fakeAdapter{}
|
||||
if _, err := adapter.Discover(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeAdapter struct{}
|
||||
|
||||
func (fakeAdapter) Discover(context.Context) (DiscoveryResult, error) { return DiscoveryResult{}, nil }
|
||||
func (fakeAdapter) Health(context.Context) (SourceHealth, error) { return SourceHealth{}, nil }
|
||||
func (fakeAdapter) Inventory(context.Context) (InventoryResult, error) { return InventoryResult{}, nil }
|
||||
func (fakeAdapter) MetricsBindings(context.Context) ([]MetricBinding, error) { return nil, nil }
|
||||
func (fakeAdapter) Events(context.Context) ([]Event, error) { return nil, nil }
|
||||
func (fakeAdapter) Capabilities(context.Context) (CapabilitySet, error) { return nil, nil }
|
||||
Reference in New Issue
Block a user