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