Files
routewatch/internal/metrics/metrics_test.go
T
clawbot 8742f1b44d
check / check (push) Canceled after 0s
Let bgp_peer_count drop to 0 (closes #92)
SetBGPPeerCount stored a count only when it was above 0, so when the last
peer the streamer knew of went down, bgp_peer_count kept its old value. It
now stores every count from 0 up.

Model: opus-5-5
2026-10-19 12:41:15 +02:00

43 lines
1.0 KiB
Go

package metrics_test
import (
"testing"
"git.eeqj.de/sneak/routewatch/internal/metrics"
)
// TestReconnectCount connects three times with a disconnect between each, the
// way the streamer does, and expects every connection after the first to count
// one reconnect.
func TestReconnectCount(t *testing.T) {
t.Parallel()
tracker := metrics.New()
tracker.SetConnected(true)
tracker.SetConnected(false)
tracker.SetConnected(true)
tracker.SetConnected(false)
tracker.SetConnected(true)
const wantReconnects = 2
if got := tracker.GetReconnectCount(); got != wantReconnects {
t.Fatalf("reconnect count = %d, want %d", got, wantReconnects)
}
}
// TestBGPPeerCountDropsToZero sets a peer count of 1 and then 0, the way the
// streamer does when the last peer's session ends, and expects 0 back.
func TestBGPPeerCountDropsToZero(t *testing.T) {
t.Parallel()
tracker := metrics.New()
tracker.SetBGPPeerCount(1)
tracker.SetBGPPeerCount(0)
if got := tracker.GetBGPPeerCount(); got != 0 {
t.Fatalf("peer count = %d after setting 0, want 0", got)
}
}