diff --git a/routingtable/adjRIBOut/path_id_manager_test.go b/routingtable/adjRIBOut/path_id_manager_test.go index e4ac49466587f0f11af3910d5fd2785e030e7cca..2940ea979e7a8f865c78da019705c4ad5595ce6e 100644 --- a/routingtable/adjRIBOut/path_id_manager_test.go +++ b/routingtable/adjRIBOut/path_id_manager_test.go @@ -55,104 +55,96 @@ X: func TestReleasePath(t *testing.T) { tests := []struct { name string - pm *pathIDManager + adds []*route.Path release *route.Path - expected *pathIDManager + expected []*route.Path wantFail bool }{ { name: "Release existent", - pm: &pathIDManager{ - ids: map[uint32]uint64{ - 0: 1, - 1: 1, - 2: 1, - }, - idByPath: map[route.BGPPath]uint32{ - route.BGPPath{ + adds: []*route.Path{ + { + BGPPath: &route.BGPPath{ LocalPref: 0, - }: 0, - route.BGPPath{ + }, + }, + { + BGPPath: &route.BGPPath{ LocalPref: 1, - }: 1, - route.BGPPath{ + }, + }, + { + BGPPath: &route.BGPPath{ LocalPref: 2, - }: 2, + }, }, - last: 2, - used: 3, }, release: &route.Path{BGPPath: &route.BGPPath{ LocalPref: 2, }}, - expected: &pathIDManager{ - ids: map[uint32]uint64{ - 0: 1, - 1: 1, - }, - idByPath: map[route.BGPPath]uint32{ - route.BGPPath{ + expected: []*route.Path{ + { + BGPPath: &route.BGPPath{ LocalPref: 0, - }: 0, - route.BGPPath{ + }, + }, + { + BGPPath: &route.BGPPath{ LocalPref: 1, - }: 1, + }, }, - last: 2, - used: 2, }, }, { name: "Release non-existent", - pm: &pathIDManager{ - ids: map[uint32]uint64{ - 0: 1, - 1: 1, - 2: 1, - }, - idByPath: map[route.BGPPath]uint32{ - route.BGPPath{ + adds: []*route.Path{ + { + BGPPath: &route.BGPPath{ LocalPref: 0, - }: 0, - route.BGPPath{ + }, + }, + { + BGPPath: &route.BGPPath{ LocalPref: 1, - }: 1, - route.BGPPath{ + }, + }, + { + BGPPath: &route.BGPPath{ LocalPref: 2, - }: 2, + }, }, - last: 2, - used: 3, }, release: &route.Path{BGPPath: &route.BGPPath{ - LocalPref: 4, + LocalPref: 5, }}, - expected: &pathIDManager{ - ids: map[uint32]uint64{ - 0: 1, - 1: 1, - 2: 1, - }, - idByPath: map[route.BGPPath]uint32{ - route.BGPPath{ + expected: []*route.Path{ + { + BGPPath: &route.BGPPath{ LocalPref: 0, - }: 0, - route.BGPPath{ + }, + }, + { + BGPPath: &route.BGPPath{ LocalPref: 1, - }: 1, - route.BGPPath{ + }, + }, + { + BGPPath: &route.BGPPath{ LocalPref: 2, - }: 2, + }, }, - last: 2, - used: 3, }, wantFail: true, }, } for _, test := range tests { - _, err := test.pm.releasePath(test.release) + pm := newPathIDManager() + for _, add := range test.adds { + pm.addPath(add) + } + + _, err := pm.releasePath(test.release) if err != nil { if test.wantFail { continue @@ -167,7 +159,12 @@ func TestReleasePath(t *testing.T) { continue } - assert.Equalf(t, test.expected, test.pm, "%s", test.name) + expectedPM := newPathIDManager() + for _, x := range test.expected { + expectedPM.addPath(x) + } + expectedPM.last++ + + assert.Equalf(t, expectedPM, pm, "%s", test.name) } } - diff --git a/routingtable/client_manager_test.go b/routingtable/client_manager_test.go index 78e2e58c4030a2e25a1b9ae228ef712fc1c67550..0106c69263224c16ba867e46e63e4027ce0b4434 100644 --- a/routingtable/client_manager_test.go +++ b/routingtable/client_manager_test.go @@ -34,6 +34,10 @@ func (m MockClient) Unregister(RouteTableClient) { return } +func (m MockClient) RouteCount() int64 { + return 0 +} + func TestClients(t *testing.T) { tests := []struct { name string diff --git a/routingtable/filter/route_filter_test.go b/routingtable/filter/route_filter_test.go index 7595df4dda19f8b4af5b668f972119878f5ab758..35d98f58ece6ed1a1a1755542d9c13d6f8f4f614 100644 --- a/routingtable/filter/route_filter_test.go +++ b/routingtable/filter/route_filter_test.go @@ -34,7 +34,7 @@ func TestInRange(t *testing.T) { }, { name: "matches end of range (22-24)", - prefix: net.NewPfx(strAddr("1.2.128.0"), 24), + prefix: net.NewPfx(strAddr("1.2.3.0"), 24), pattern: net.NewPfx(strAddr("1.2.0.0"), 22), begin: 22, end: 24, diff --git a/routingtable/mock_client.go b/routingtable/mock_client.go index 806dd2b3b29865d6821002cda1c2c7dc4c360279..30d613c6eac349585bfeca2cedd6bcacc91462be 100644 --- a/routingtable/mock_client.go +++ b/routingtable/mock_client.go @@ -50,3 +50,7 @@ func (m *RTMockClient) RemovePath(pfx net.Prefix, p *route.Path) bool { m.removePathParams.Path = p return true } + +func (m *RTMockClient) RouteCount() int64 { + return 0 +}