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

Fixing tests

parent 50e70a58
Branches
Tags
No related merge requests found
......@@ -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)
}
}
......@@ -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
......
......@@ -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,
......
......@@ -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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment