Files
urutau/internal/fed/fed_test.go
T
Lucas RayanandClaude Opus 5.5 8546d14cef
CI / Format and vet (pull_request) Failing after 53s
CI / Dependency audit (pull_request) Successful in 33s
CI / Tests (Linux, race detector) (pull_request) Successful in 2m1s
CI / Docker images (build and smoke test) (pull_request) Failing after 47s
feat!: Urutau 2.0.0, ultralight probes and a single analysis hub
Each server runs an ultralight probe (scratch image, ~7 MiB RSS) that
tails the logs, ships raw lines to the hub over HTTPS with an on-disk
spool, and applies enforce decisions locally. The hub keeps one node per
probe (primary node = the 1.x data dir, unchanged), does all analysis and
serves the UI. Peer federation is removed. 'urutau import' brings 1.x
data dirs in with hash and count verification. UI: probes page, host
qualified incidents, IPs never wrap, egress heatmap labels, live and
replay globes no longer auto-rotate, replay repeat, live traffic metrics.

BREAKING CHANGE: URUTAU_PEERS, URUTAU_PEER_* and /api/v1/peer/* are gone;
log path variables move from the hub to the probe. See docs/migration-2.0.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:14:50 -03:00

51 lines
1.7 KiB
Go

package fed
import (
"context"
"encoding/json"
"testing"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
)
type fake struct {
name string
online bool
}
func (f fake) Name() string { return f.name }
func (f fake) Export(rg store.Range) store.PeerExport {
return store.PeerExport{V: store.ExportVersion, Summary: store.Summary{Host: f.name, Hosts: []store.HostInfo{{Name: f.name, Self: true}}}, Traffic: map[string]store.TrafficData{}}
}
func (f fake) Study(q store.PeriodQuery) store.PeerStudy { return store.PeerStudy{} }
func (f fake) Egress(a, b int64) json.RawMessage { return json.RawMessage(`{"findings":[]}`) }
func (f fake) Subscribe() (<-chan store.LiveEvent, func()) {
return make(chan store.LiveEvent), func() {}
}
func (f fake) SubscribeVisits() (<-chan store.VisitMsg, func()) {
return make(chan store.VisitMsg), func() {}
}
func (f fake) Online() bool { return f.online }
func (f fake) Location() *store.Location { return nil }
func TestHubServesBackendsEvenOffline(t *testing.T) {
h := NewHub(func() []Backend { return []Backend{fake{"b", false}, fake{"a", true}} })
if got := h.PeerNames(); len(got) != 2 || got[0] != "a" || !h.Has("b") || h.Has("c") {
t.Fatalf("%v", got)
}
rg := store.ParseRange("24h")
if s := h.SummariesFor(context.Background(), rg, ""); len(s) != 2 || s[0].Host != "a" || s[0].Hosts[0].Self {
t.Fatalf("%+v", s)
}
if s := h.SummariesFor(context.Background(), rg, "b"); len(s) != 1 {
t.Fatalf("only: %+v", s)
}
hosts := h.Hosts()
if len(hosts) != 2 || hosts[0].Online != true || hosts[1].Online != false {
t.Fatalf("%+v", hosts)
}
if m := h.EgressFor(context.Background(), 0, 1, ""); len(m) != 2 {
t.Fatalf("%v", m)
}
}