diff --git a/routingtable/BUILD.bazel b/routingtable/BUILD.bazel index fdea62781ff59b143bf04d143ee5eae9385e0bc6..7715828736aa4c22a3ddbdf69dc27646464344d9 100644 --- a/routingtable/BUILD.bazel +++ b/routingtable/BUILD.bazel @@ -6,6 +6,7 @@ go_library( "client_interface.go", "client_manager.go", "contributing_asn_list.go", + "mock_client.go", "neighbor.go", "rib_interface.go", "table.go", diff --git a/routingtable/adjRIBIn/adj_rib_in_test.go b/routingtable/adjRIBIn/adj_rib_in_test.go index 0eeacc3e21162d9fac3cd2461dc788083f08796e..9939e805d0dc73bd9e9f6555463c343f6ca16bcc 100644 --- a/routingtable/adjRIBIn/adj_rib_in_test.go +++ b/routingtable/adjRIBIn/adj_rib_in_test.go @@ -1,56 +1,16 @@ package adjRIBIn import ( - "fmt" "testing" - "github.com/bio-routing/bio-rd/routingtable/filter" - "github.com/stretchr/testify/assert" "github.com/bio-routing/bio-rd/net" "github.com/bio-routing/bio-rd/route" "github.com/bio-routing/bio-rd/routingtable" + "github.com/bio-routing/bio-rd/routingtable/filter" ) -type RTMockClient struct { - removePathParams struct { - pfx net.Prefix - path *route.Path - } -} - -func NewRTMockClient() *RTMockClient { - return &RTMockClient{} -} - -func (m *RTMockClient) AddPath(pfx net.Prefix, p *route.Path) error { - return nil -} - -func (m *RTMockClient) UpdateNewClient(client routingtable.RouteTableClient) error { - return fmt.Errorf("Not implemented") -} - -func (m *RTMockClient) Register(routingtable.RouteTableClient) { - return -} - -func (m *RTMockClient) RegisterWithOptions(routingtable.RouteTableClient, routingtable.ClientOptions) { - return -} - -func (m *RTMockClient) Unregister(routingtable.RouteTableClient) { - return -} - -// RemovePath removes the path for prefix `pfx` -func (m *RTMockClient) RemovePath(pfx net.Prefix, p *route.Path) bool { - m.removePathParams.pfx = pfx - m.removePathParams.path = p - return true -} - func TestAddPath(t *testing.T) { tests := []struct { name string @@ -116,18 +76,19 @@ func TestAddPath(t *testing.T) { for _, test := range tests { adjRIBIn := New(filter.NewAcceptAllFilter(), routingtable.NewContributingASNs()) - mc := NewRTMockClient() + mc := routingtable.NewRTMockClient() adjRIBIn.ClientManager.Register(mc) for _, route := range test.routes { adjRIBIn.AddPath(route.Prefix(), route.Paths()[0]) } - if mc.removePathParams.pfx != test.removePfx { - t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, mc.removePathParams.pfx.String(), test.removePfx.String()) + removePathParams := mc.GetRemovePathParams() + if removePathParams.Pfx != test.removePfx { + t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, removePathParams.Pfx.String(), test.removePfx.String()) } - assert.Equal(t, test.removePath, mc.removePathParams.path) + assert.Equal(t, test.removePath, removePathParams.Path) assert.Equal(t, test.expected, adjRIBIn.rt.Dump()) } } @@ -211,17 +172,19 @@ func TestRemovePath(t *testing.T) { adjRIBIn.AddPath(route.Prefix(), route.Paths()[0]) } - mc := NewRTMockClient() + mc := routingtable.NewRTMockClient() adjRIBIn.ClientManager.Register(mc) adjRIBIn.RemovePath(test.removePfx, test.removePath) if test.wantPropagation { - if mc.removePathParams.pfx != test.removePfx { - t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, mc.removePathParams.pfx.String(), test.removePfx.String()) + removePathParams := mc.GetRemovePathParams() + if removePathParams.Pfx != test.removePfx { + t.Errorf("Test %q failed: Call to RemovePath did not propagate prefix properly: Got: %s Want: %s", test.name, removePathParams.Pfx.String(), test.removePfx.String()) } - assert.Equal(t, test.removePath, mc.removePathParams.path) + assert.Equal(t, test.removePath, removePathParams.Path) } else { - if mc.removePathParams.pfx != net.NewPfx(0, 0) { + removePathParams := mc.GetRemovePathParams() + if removePathParams.Pfx != net.NewPfx(0, 0) { t.Errorf("Test %q failed: Call to RemovePath propagated unexpectedly", test.name) } } diff --git a/routingtable/mock_client.go b/routingtable/mock_client.go new file mode 100644 index 0000000000000000000000000000000000000000..806dd2b3b29865d6821002cda1c2c7dc4c360279 --- /dev/null +++ b/routingtable/mock_client.go @@ -0,0 +1,52 @@ +package routingtable + +import ( + "fmt" + + "github.com/bio-routing/bio-rd/net" + "github.com/bio-routing/bio-rd/route" +) + +type RemovePathParams struct { + Pfx net.Prefix + Path *route.Path +} + +type RTMockClient struct { + removePathParams RemovePathParams +} + +func NewRTMockClient() *RTMockClient { + return &RTMockClient{} +} + +func (m *RTMockClient) GetRemovePathParams() RemovePathParams { + return m.removePathParams +} + +func (m *RTMockClient) AddPath(pfx net.Prefix, p *route.Path) error { + return nil +} + +func (m *RTMockClient) UpdateNewClient(client RouteTableClient) error { + return fmt.Errorf("Not implemented") +} + +func (m *RTMockClient) Register(RouteTableClient) { + return +} + +func (m *RTMockClient) RegisterWithOptions(RouteTableClient, ClientOptions) { + return +} + +func (m *RTMockClient) Unregister(RouteTableClient) { + return +} + +// RemovePath removes the path for prefix `pfx` +func (m *RTMockClient) RemovePath(pfx net.Prefix, p *route.Path) bool { + m.removePathParams.Pfx = pfx + m.removePathParams.Path = p + return true +}