CI / changes (push) Successful in 8s
CI / commitlint (push) Has been skipped
CI / openapi (push) Has been skipped
CI / web (push) Successful in 35s
CI / go (push) Successful in 52s
CI / bird2 (push) Successful in 16s
CI / release (push) Successful in 3m58s
- Added `PollError` field to `peerSessionOnSpeaker` and `liveSpeakerPoll` types to capture polling errors for speakers. - Updated `matchPeerOnSpeakers` function to handle polling errors and adjust session state reporting. - Modified frontend components to display polling error messages alongside session states, improving user visibility into peer connection statuses. - Enhanced API response structure to include live speaker polling information, facilitating better monitoring of speaker health.
80 lines
3.0 KiB
Go
80 lines
3.0 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"evobgp/internal/birdfmt"
|
|
"evobgp/internal/store"
|
|
)
|
|
|
|
func TestMatchPeerOnSpeakers_establishedOnReplica(t *testing.T) {
|
|
peer := &store.BGPPeer{
|
|
ID: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
|
|
Neighbor: "198.51.100.2",
|
|
}
|
|
views := []speakerBGPLive{
|
|
{
|
|
SpeakerID: "master-id",
|
|
Label: "CP · bgp.shz.su",
|
|
Sessions: []birdfmt.BGPSession{
|
|
{Name: birdfmt.PeerProtocolName(peer.ID), Neighbor: "198.51.100.2", State: "Established"},
|
|
},
|
|
},
|
|
{
|
|
SpeakerID: "replica-id",
|
|
Label: "bgp2.shz.su",
|
|
Sessions: []birdfmt.BGPSession{
|
|
{Name: birdfmt.PeerProtocolName(peer.ID), Neighbor: "198.51.100.2", State: "Established"},
|
|
},
|
|
},
|
|
}
|
|
state, connID, connLabel, established, on, mismatch := matchPeerOnSpeakers(peer, views)
|
|
if state != "Established" || connID != "" || connLabel != "CP · bgp.shz.su, bgp2.shz.su" {
|
|
t.Fatalf("got state=%q conn=%q label=%q", state, connID, connLabel)
|
|
}
|
|
if mismatch || len(on) != 2 || len(established) != 2 {
|
|
t.Fatalf("on=%+v established=%+v mismatch=%v", on, established, mismatch)
|
|
}
|
|
}
|
|
|
|
func TestMatchPeerOnSpeakers_multipleEstablished(t *testing.T) {
|
|
peer := &store.BGPPeer{ID: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", Neighbor: "198.51.100.2/32"}
|
|
views := []speakerBGPLive{
|
|
{SpeakerID: "a", Label: "n1", Sessions: []birdfmt.BGPSession{{Name: birdfmt.PeerProtocolName(peer.ID), State: "Established"}}},
|
|
{SpeakerID: "b", Label: "n2", Sessions: []birdfmt.BGPSession{{Name: birdfmt.PeerProtocolName(peer.ID), State: "Established"}}},
|
|
}
|
|
_, connID, label, established, on, mismatch := matchPeerOnSpeakers(peer, views)
|
|
if mismatch || connID != "" || label != "n1, n2" || len(established) != 2 || len(on) != 2 {
|
|
t.Fatalf("connID=%q label=%q established=%+v on=%+v mismatch=%v", connID, label, established, on, mismatch)
|
|
}
|
|
}
|
|
|
|
func TestMatchPeerOnSpeakers_mismatchConfiguredSpeaker(t *testing.T) {
|
|
replica := "replica-id"
|
|
peer := &store.BGPPeer{
|
|
ID: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
|
|
Neighbor: "198.51.100.2",
|
|
SpeakerID: &replica,
|
|
}
|
|
views := []speakerBGPLive{
|
|
{SpeakerID: "master-id", Label: "CP", Sessions: []birdfmt.BGPSession{{Name: birdfmt.PeerProtocolName(peer.ID), State: "Established"}}},
|
|
{SpeakerID: replica, Label: "bgp2", Sessions: []birdfmt.BGPSession{{Name: birdfmt.PeerProtocolName(peer.ID), State: "Idle"}}},
|
|
}
|
|
_, _, _, _, _, mismatch := matchPeerOnSpeakers(peer, views)
|
|
if !mismatch {
|
|
t.Fatal("expected mismatch when configured replica has no Established")
|
|
}
|
|
}
|
|
|
|
func TestMatchPeerOnSpeakers_pollError(t *testing.T) {
|
|
peer := &store.BGPPeer{ID: "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee", Neighbor: "198.51.100.2"}
|
|
views := []speakerBGPLive{
|
|
{Label: "CP (local BIRD)", Sessions: []birdfmt.BGPSession{{Name: birdfmt.PeerProtocolName(peer.ID), State: "Established"}}},
|
|
{SpeakerID: "replica-id", Label: "bgp2.shz.su", Error: "HTTP 404: Not Found"},
|
|
}
|
|
_, _, _, established, on, _ := matchPeerOnSpeakers(peer, views)
|
|
if len(established) != 1 || len(on) != 2 || on[1].PollError == "" {
|
|
t.Fatalf("on=%+v established=%+v", on, established)
|
|
}
|
|
}
|