Skip to content
Snippets Groups Projects
Commit c27a029b authored by Oliver Herms's avatar Oliver Herms
Browse files

Fixing client manager

parent c92109a9
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ func (r *Route) AddPath(p *Path) {
r.paths = append(r.paths, p)
}
// RemovePath removes path `rm` from route `r`. Returns length of path list after removing path `rm`
// RemovePath removes path `p` from route `r`. Returns length of path list after removing path `rm`
func (r *Route) RemovePath(p *Path) int {
if p == nil {
return len(r.paths)
......
......@@ -32,7 +32,8 @@ func (c *ClientManager) Unregister(client RouteTableClient) {
}
// Clients returns a list of registered clients
func (c *ClientManager) Clients() (ret []RouteTableClient) {
func (c *ClientManager) Clients() []RouteTableClient {
ret := make([]RouteTableClient, 0)
for rtc := range c.clients {
ret = append(ret, rtc)
}
......
package routingtable
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
)
type MockClient struct {
foo int
}
func (m MockClient) AddPath(net.Prefix, *route.Path) error {
return nil
}
func (m MockClient) RemovePath(net.Prefix, *route.Path) bool {
return false
}
func (m MockClient) UpdateNewClient(RouteTableClient) error {
return nil
}
func TestClients(t *testing.T) {
tests := []struct {
name string
clients []MockClient
expected []RouteTableClient
}{
{
name: "No clients",
clients: []MockClient{},
expected: []RouteTableClient{},
},
{
name: "No clients",
clients: []MockClient{
MockClient{
foo: 1,
},
MockClient{
foo: 2,
},
},
expected: []RouteTableClient{
MockClient{
foo: 1,
},
MockClient{
foo: 2,
},
},
},
}
for _, test := range tests {
cm := NewClientManager(MockClient{})
for _, client := range test.clients {
cm.Register(client)
}
ret := cm.Clients()
assert.Equal(t, test.expected, ret)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment