Skip to content
Snippets Groups Projects
Unverified Commit ee160eb1 authored by Daniel Czerwonk's avatar Daniel Czerwonk Committed by GitHub
Browse files

Merge pull request #88 from BarbarossaTM/test/table

Fix counting bug in routingtable and update tests to cover that area.
parents eeaf11c8 4afe0680
No related branches found
No related tags found
No related merge requests found
...@@ -10,9 +10,10 @@ import ( ...@@ -10,9 +10,10 @@ import (
func TestAddPath(t *testing.T) { func TestAddPath(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
routes []*route.Route routes []*route.Route
expected *node expected *node
expectedCount int64
}{ }{
{ {
name: "Insert first node", name: "Insert first node",
...@@ -23,6 +24,7 @@ func TestAddPath(t *testing.T) { ...@@ -23,6 +24,7 @@ func TestAddPath(t *testing.T) {
route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil),
skip: 8, skip: 8,
}, },
expectedCount: 1,
}, },
{ {
name: "Insert duplicate node", name: "Insert duplicate node",
...@@ -36,6 +38,7 @@ func TestAddPath(t *testing.T) { ...@@ -36,6 +38,7 @@ func TestAddPath(t *testing.T) {
route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil), route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 0, 0, 0), 8), nil),
skip: 8, skip: 8,
}, },
expectedCount: 1,
}, },
{ {
name: "Insert triangle", name: "Insert triangle",
...@@ -54,6 +57,7 @@ func TestAddPath(t *testing.T) { ...@@ -54,6 +57,7 @@ func TestAddPath(t *testing.T) {
route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), nil), route: route.NewRoute(net.NewPfx(net.IPv4FromOctets(10, 128, 0, 0), 9), nil),
}, },
}, },
expectedCount: 3,
}, },
{ {
name: "Insert disjunct prefixes", name: "Insert disjunct prefixes",
...@@ -73,6 +77,7 @@ func TestAddPath(t *testing.T) { ...@@ -73,6 +77,7 @@ func TestAddPath(t *testing.T) {
skip: 16, skip: 16,
}, },
}, },
expectedCount: 2,
}, },
{ {
name: "Insert disjunct prefixes plus one child low", name: "Insert disjunct prefixes plus one child low",
...@@ -102,6 +107,7 @@ func TestAddPath(t *testing.T) { ...@@ -102,6 +107,7 @@ func TestAddPath(t *testing.T) {
skip: 16, skip: 16,
}, },
}, },
expectedCount: 4,
}, },
{ {
name: "Insert disjunct prefixes plus one child high", name: "Insert disjunct prefixes plus one child high",
...@@ -135,6 +141,7 @@ func TestAddPath(t *testing.T) { ...@@ -135,6 +141,7 @@ func TestAddPath(t *testing.T) {
}, },
}, },
}, },
expectedCount: 5,
}, },
} }
...@@ -145,6 +152,7 @@ func TestAddPath(t *testing.T) { ...@@ -145,6 +152,7 @@ func TestAddPath(t *testing.T) {
} }
assert.Equal(t, test.expected, rt.root) assert.Equal(t, test.expected, rt.root)
assert.Equal(t, test.expectedCount, rt.GetRouteCount())
} }
} }
...@@ -342,11 +350,12 @@ func TestLPM(t *testing.T) { ...@@ -342,11 +350,12 @@ func TestLPM(t *testing.T) {
func TestRemovePath(t *testing.T) { func TestRemovePath(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
routes []*route.Route routes []*route.Route
removePfx net.Prefix removePfx net.Prefix
removePath *route.Path removePath *route.Path
expected []*route.Route expected []*route.Route
expectedCount int64
}{ }{
{ {
name: "Remove a path that is the only one for a prefix", name: "Remove a path that is the only one for a prefix",
...@@ -379,6 +388,7 @@ func TestRemovePath(t *testing.T) { ...@@ -379,6 +388,7 @@ func TestRemovePath(t *testing.T) {
BGPPath: &route.BGPPath{}, BGPPath: &route.BGPPath{},
}), }),
}, },
expectedCount: 2,
}, },
{ {
name: "Remove a path that is one of two for a prefix", name: "Remove a path that is one of two for a prefix",
...@@ -427,6 +437,7 @@ func TestRemovePath(t *testing.T) { ...@@ -427,6 +437,7 @@ func TestRemovePath(t *testing.T) {
BGPPath: &route.BGPPath{}, BGPPath: &route.BGPPath{},
}), }),
}, },
expectedCount: 3,
}, },
} }
...@@ -448,6 +459,7 @@ func TestRemovePath(t *testing.T) { ...@@ -448,6 +459,7 @@ func TestRemovePath(t *testing.T) {
} }
assert.Equal(t, rtExpected.Dump(), rt.Dump()) assert.Equal(t, rtExpected.Dump(), rt.Dump())
assert.Equal(t, test.expectedCount, rt.GetRouteCount())
} }
} }
......
...@@ -118,8 +118,10 @@ func (n *node) addPath(pfx net.Prefix, p *route.Path) (*node, bool) { ...@@ -118,8 +118,10 @@ func (n *node) addPath(pfx net.Prefix, p *route.Path) (*node, bool) {
currentPfx := n.route.Prefix() currentPfx := n.route.Prefix()
if currentPfx == pfx { if currentPfx == pfx {
n.route.AddPath(p) n.route.AddPath(p)
// Store previous dummy-ness to check it this node became new
dummy := n.dummy
n.dummy = false n.dummy = false
return n, true return n, dummy == true
} }
// is pfx NOT a subnet of this node? // is pfx NOT a subnet of this node?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment