Skip to content
Snippets Groups Projects
Commit 6d5dbf0b authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

fixed bug in term processing

parent 86f17a1f
Branches
Tags
No related merge requests found
...@@ -12,11 +12,11 @@ import ( ...@@ -12,11 +12,11 @@ import (
type mockAction struct { type mockAction struct {
} }
func (*mockAction) Do(p net.Prefix, pa *route.Path) (*route.Path, bool) { func (*mockAction) Do(p net.Prefix, pa *route.Path) actions.Result {
cp := *pa cp := *pa
cp.Type = route.OSPFPathType cp.Type = route.OSPFPathType
return &cp, false return actions.Result{Path: &cp}
} }
func TestProcess(t *testing.T) { func TestProcess(t *testing.T) {
...@@ -25,7 +25,7 @@ func TestProcess(t *testing.T) { ...@@ -25,7 +25,7 @@ func TestProcess(t *testing.T) {
prefix net.Prefix prefix net.Prefix
path *route.Path path *route.Path
from []*TermCondition from []*TermCondition
then []FilterAction then []Action
expectReject bool expectReject bool
expectModified bool expectModified bool
}{ }{
...@@ -34,7 +34,7 @@ func TestProcess(t *testing.T) { ...@@ -34,7 +34,7 @@ func TestProcess(t *testing.T) {
prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), prefix: net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8),
path: &route.Path{}, path: &route.Path{},
from: []*TermCondition{}, from: []*TermCondition{},
then: []FilterAction{ then: []Action{
&actions.AcceptAction{}, &actions.AcceptAction{},
}, },
expectReject: false, expectReject: false,
...@@ -48,7 +48,7 @@ func TestProcess(t *testing.T) { ...@@ -48,7 +48,7 @@ func TestProcess(t *testing.T) {
NewTermConditionWithPrefixLists( NewTermConditionWithPrefixLists(
NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8))), NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8))),
}, },
then: []FilterAction{ then: []Action{
&actions.AcceptAction{}, &actions.AcceptAction{},
}, },
expectReject: false, expectReject: false,
...@@ -62,7 +62,7 @@ func TestProcess(t *testing.T) { ...@@ -62,7 +62,7 @@ func TestProcess(t *testing.T) {
NewTermConditionWithPrefixLists( NewTermConditionWithPrefixLists(
NewPrefixList(net.NewPfx(net.IPv4(0), 32))), NewPrefixList(net.NewPfx(net.IPv4(0), 32))),
}, },
then: []FilterAction{ then: []Action{
&actions.AcceptAction{}, &actions.AcceptAction{},
}, },
expectReject: false, expectReject: false,
...@@ -76,7 +76,7 @@ func TestProcess(t *testing.T) { ...@@ -76,7 +76,7 @@ func TestProcess(t *testing.T) {
NewTermConditionWithPrefixLists( NewTermConditionWithPrefixLists(
NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8))), NewPrefixList(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8))),
}, },
then: []FilterAction{ then: []Action{
&mockAction{}, &mockAction{},
}, },
expectReject: false, expectReject: false,
...@@ -90,7 +90,7 @@ func TestProcess(t *testing.T) { ...@@ -90,7 +90,7 @@ func TestProcess(t *testing.T) {
NewTermConditionWithRouteFilters( NewTermConditionWithRouteFilters(
NewRouteFilter(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), Exact())), NewRouteFilter(net.NewPfx(net.IPv4FromOctets(100, 64, 0, 1), 8), Exact())),
}, },
then: []FilterAction{ then: []Action{
&mockAction{}, &mockAction{},
&actions.AcceptAction{}, &actions.AcceptAction{},
}, },
...@@ -109,7 +109,7 @@ func TestProcess(t *testing.T) { ...@@ -109,7 +109,7 @@ func TestProcess(t *testing.T) {
}, },
}, },
}, },
then: []FilterAction{ then: []Action{
&actions.AcceptAction{}, &actions.AcceptAction{},
}, },
expectReject: false, expectReject: false,
...@@ -118,18 +118,18 @@ func TestProcess(t *testing.T) { ...@@ -118,18 +118,18 @@ func TestProcess(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(te *testing.T) { t.Run(test.name, func(t *testing.T) {
term := NewTerm(test.from, test.then) term := NewTerm(test.from, test.then)
pa, reject := term.Process(test.prefix, test.path) res := term.Process(test.prefix, test.path)
assert.Equal(te, test.expectReject, reject, "reject") assert.Equal(t, test.expectReject, res.Reject, "reject")
if pa != test.path && !test.expectModified { if res.Path != test.path && !test.expectModified {
te.Fatal("expected path to be not modified but was") t.Fatal("expected path to be not modified but was")
} }
if pa == test.path && test.expectModified { if res.Path == test.path && test.expectModified {
te.Fatal("expected path to be modified but was same reference") t.Fatal("expected path to be modified but was same reference")
} }
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment