CI / changes (push) Successful in 9s
CI / commitlint (push) Has been skipped
CI / openapi (push) Successful in 24s
CI / web (push) Successful in 29s
CI / go (push) Successful in 43s
CI / bird2 (push) Successful in 15s
CI / release (push) Successful in 3m29s
- Introduced new schemas for `SpeakerLiveStatus`, `BgpSessionLive`, and `LiveSpeakerPoll` in OpenAPI documentation to support live status queries. - Enhanced the `/v1/speakers` endpoint to include a `live` query parameter, allowing retrieval of real-time speaker and BGP status. - Updated the HTTP API to collect and return live status data for speakers, improving monitoring capabilities. - Modified frontend components to display live status information, enhancing user visibility into speaker health and BGP session states. - Added a new endpoint `/v1/bird/status` for retrieving the local BIRD status, further enriching the network monitoring features.
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"evobgp/internal/birdfmt"
|
|
"evobgp/internal/nodedispatch"
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
func TestCountBGPSessions(t *testing.T) {
|
|
total, est := countBGPSessions([]birdfmt.BGPSession{
|
|
{Name: "p1", State: "Established"},
|
|
{Name: "p2", State: "Idle"},
|
|
{Name: "p3", State: "established"},
|
|
})
|
|
if total != 3 || est != 2 {
|
|
t.Fatalf("total=%d established=%d", total, est)
|
|
}
|
|
}
|
|
|
|
func TestSpeakerLiveStatusJSON_masterUsesBirdPoll(t *testing.T) {
|
|
sp := &store.Speaker{ID: "m1", Role: "master", Endpoint: "https://cp.example"}
|
|
view := speakerBGPLive{
|
|
SpeakerID: "m1",
|
|
Label: "CP · cp.example",
|
|
Sessions: []birdfmt.BGPSession{
|
|
{Name: "evobgp_peer_x", State: "Established"},
|
|
},
|
|
}
|
|
m := speakerLiveStatusJSON(sp, view, nil)
|
|
if m["agent_ok"] != true || m["bgp_established"] != 1 || m["bgp_sessions_total"] != 1 {
|
|
t.Fatalf("got %#v", m)
|
|
}
|
|
}
|
|
|
|
func TestSpeakerLiveStatusJSON_replicaWithHealth(t *testing.T) {
|
|
sp := &store.Speaker{
|
|
ID: "r1",
|
|
Role: "replica",
|
|
Endpoint: "https://node.example",
|
|
MetaJSON: `{"agent_domain":"node.example","agent_secret":"s"}`,
|
|
}
|
|
view := speakerBGPLive{
|
|
SpeakerID: "r1",
|
|
Label: "node.example",
|
|
Sessions: []birdfmt.BGPSession{{Name: "p", State: "Idle"}},
|
|
}
|
|
health := &nodedispatch.AgentHealthResult{
|
|
OK: true,
|
|
LastSyncAt: "2026-05-21T12:00:00Z",
|
|
LastAppliedRevisionID: "rev-1",
|
|
}
|
|
m := speakerLiveStatusJSON(sp, view, health)
|
|
if m["agent_ok"] != true || m["agent_last_sync_at"] != "2026-05-21T12:00:00Z" {
|
|
t.Fatalf("got %#v", m)
|
|
}
|
|
if m["bgp_established"] != 0 || m["bgp_poll_ok"] != true {
|
|
t.Fatalf("bgp fields: %#v", m)
|
|
}
|
|
}
|
|
|
|
func TestSpeakerLiveStatusJSON_pollError(t *testing.T) {
|
|
sp := &store.Speaker{ID: "r1", Role: "replica", MetaJSON: `{"agent_domain":"x.example"}`}
|
|
view := speakerBGPLive{SpeakerID: "r1", Label: "x.example", Error: "HTTP 503"}
|
|
health := &nodedispatch.AgentHealthResult{OK: false, Error: "timeout"}
|
|
m := speakerLiveStatusJSON(sp, view, health)
|
|
if m["bgp_poll_ok"] != false || m["bgp_poll_error"] != "HTTP 503" {
|
|
t.Fatalf("got %#v", m)
|
|
}
|
|
if m["agent_ok"] != false {
|
|
t.Fatalf("agent_ok: %#v", m)
|
|
}
|
|
}
|