diff --git a/rt/routing_table_test.go b/rt/routing_table_test.go index e4f4e993bc7162074d8860f8e8be42334087cfb7..602c1da960ec9be66196decf59eb47e2794a5bfc 100644 --- a/rt/routing_table_test.go +++ b/rt/routing_table_test.go @@ -146,6 +146,79 @@ func TestRemovePath(t *testing.T) { } } +func TestRemovePfx(t *testing.T) { + tests := []struct { + name string + routes []*Route + remove []*net.Prefix + expected []*Route + }{ + { + name: "Remove non-existent prefix", + routes: []*Route{ + NewRoute(net.NewPfx(strAddr("10.0.0.0"), 8), []*Path{ + { + Type: BGPPathType, + BGPPath: &BGPPath{}, + }, + }), + NewRoute(net.NewPfx(strAddr("100.0.0.0"), 8), []*Path{ + { + Type: BGPPathType, + BGPPath: &BGPPath{}, + }, + }), + }, + remove: []*net.Prefix{ + net.NewPfx(0, 0), + }, + expected: []*Route{ + NewRoute(net.NewPfx(strAddr("10.0.0.0"), 8), []*Path{ + { + Type: BGPPathType, + BGPPath: &BGPPath{}, + }, + }), + NewRoute(net.NewPfx(strAddr("100.0.0.0"), 8), []*Path{ + { + Type: BGPPathType, + BGPPath: &BGPPath{}, + }, + }), + }, + }, + { + name: "Remove final prefix", + routes: []*Route{ + NewRoute(net.NewPfx(strAddr("10.0.0.0"), 8), []*Path{ + { + Type: BGPPathType, + BGPPath: &BGPPath{}, + }, + }), + }, + remove: []*net.Prefix{ + net.NewPfx(strAddr("10.0.0.0"), 8), + }, + expected: []*Route{}, + }, + } + + for _, test := range tests { + lpm := New() + for _, route := range test.routes { + lpm.Insert(route) + } + + for _, pfx := range test.remove { + lpm.RemovePfx(pfx) + } + + res := lpm.Dump() + assert.Equal(t, test.expected, res) + } +} + func strAddr(s string) uint32 { ret, _ := net.StrToAddr(s) return ret