Files
EvoBGP/internal/store/speaker_meta_test.go
T
Denozordec 9639a03bfe
CI / changes (push) Successful in 9s
CI / commitlint (push) Has been skipped
CI / openapi (push) Has been skipped
CI / web (push) Successful in 39s
CI / go (push) Successful in 58s
CI / bird2 (push) Successful in 16s
CI / release (push) Successful in 4m18s
feat(store): add test for clearing dispatch error on successful merge
- Introduced a new test case in speaker_meta_test.go to verify that the LastDispatchError is cleared when a successful dispatch status is merged.
- Updated MergeSpeakerMetaJSON function in speaker_meta.go to clear LastDispatchError if LastDispatchStatus is "ok".
- Enhanced speakerDispatchError function in network-metrics.ts to handle stale dispatch errors after successful agent sync.
2026-05-21 18:10:51 +07:00

58 lines
1.6 KiB
Go

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