package network import ( "context" "errors" "testing" "time" "github.com/itworx/pulse/internal/host" "github.com/itworx/pulse/internal/service" ) type errorHostProvider struct{} func (errorHostProvider) Snapshot(context.Context) (host.Snapshot, error) { return host.Snapshot{}, errors.New("host unavailable") } type staticServiceProvider struct{ snapshot service.Snapshot } func (p staticServiceProvider) Snapshot(context.Context) (service.Snapshot, error) { return p.snapshot, nil } func TestAggregatorKeepsPartialSourcesAvailable(t *testing.T) { now := time.Date(2026, 8, 2, 12, 0, 0, 0, time.UTC) provider := Aggregator{Host: errorHostProvider{}, Services: staticServiceProvider{snapshot: service.Snapshot{ObservedAt: now}}, Now: func() time.Time { return now }} snapshot, err := provider.Snapshot(context.Background()) if err != nil { t.Fatal(err) } if snapshot.Source.State != StateUnknown || snapshot.Health[0].State != StateUnknown || snapshot.Health[2].State != StateUnknown { t.Fatalf("partial source did not remain unknown: %+v", snapshot) } }