Newer
Older
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 (m MockClient) Register(RouteTableClient) {
return
}
func (m MockClient) RegisterWithOptions(RouteTableClient, ClientOptions) {
return
}
func (m MockClient) Unregister(RouteTableClient) {
return
}
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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()
for _, exp := range test.expected {
found := false
for _, client := range ret {
if exp == client {
found = true
continue
}
}
if !found {
t.Errorf("Test %q failed: Client %v not found in result: %v", test.name, exp, ret)
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
func TestGetMaxPaths(t *testing.T) {
tests := []struct {
name string
clientOptions ClientOptions
ecmpPaths uint
expected uint
}{
{
name: "Test #1",
clientOptions: ClientOptions{
BestOnly: true,
},
ecmpPaths: 8,
expected: 1,
},
{
name: "Test #2",
clientOptions: ClientOptions{
EcmpOnly: true,
},
ecmpPaths: 8,
expected: 8,
},
{
name: "Test #3",
clientOptions: ClientOptions{
MaxPaths: 100,
},
ecmpPaths: 10,
expected: 100,
},
}
for _, test := range tests {
res := test.clientOptions.GetMaxPaths(test.ecmpPaths)
assert.Equal(t, test.expected, res)
}
}