package store_test import ( "testing" "evobgp/internal/store" ) func TestParseSpeakerMeta_defaults(t *testing.T) { t.Parallel() m := store.ParseSpeakerMeta(`{"agent_domain":"bgp1.example.com"}`) if m.AgentPort != 8443 { t.Fatalf("default port: got %d", m.AgentPort) } if m.AgentDomain != "bgp1.example.com" { t.Fatalf("domain: %q", m.AgentDomain) } } func TestIPv4FromEndpoint(t *testing.T) { t.Parallel() if got := store.IPv4FromEndpoint("https://203.0.113.10:8443"); got != "203.0.113.10" { t.Fatalf("got %q", got) } if got := store.IPv4FromEndpoint("bgp-dc2.example.com"); got != "" { t.Fatalf("hostname should be empty, got %q", got) } } func TestAgentSyncURL(t *testing.T) { t.Parallel() u := store.AgentSyncURL(store.SpeakerMeta{AgentDomain: "node.example.com"}) if u != "https://node.example.com/v1/agent/sync" { t.Fatalf("got %q", u) } } func TestMergeSpeakerMetaJSON_clearsDispatchErrorOnOk(t *testing.T) { t.Parallel() existing := store.SpeakerMetaJSON(store.SpeakerMeta{ LastDispatchError: "HTTP 502: bundle 403", LastDispatchStatus: "error", SyncStatus: "error", }) merged := store.MergeSpeakerMetaJSON(existing, store.SpeakerMeta{ LastDispatchStatus: "ok", SyncStatus: "synced", LastDispatchAt: "2026-05-21T15:06:43Z", }) m := store.ParseSpeakerMeta(merged) if m.LastDispatchError != "" { t.Fatalf("LastDispatchError should clear on ok dispatch, got %q", m.LastDispatchError) } if m.LastDispatchStatus != "ok" || m.SyncStatus != "synced" { t.Fatalf("status: dispatch=%q sync=%q", m.LastDispatchStatus, m.SyncStatus) } }