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

resored filter tests

parent 9b2f55a0
No related branches found
No related tags found
No related merge requests found
package filter
/*func TestAddPath(t *testing.T) {
tests := []struct {
name string
prefix net.Prefix
path *route.Path
term *Term
exptectCalled bool
expectModified bool
}{
{
name: "accept",
prefix: net.NewPfx(0, 0),
path: &route.Path{},
term: &Term{
then: []FilterAction{
&actions.AcceptAction{},
},
},
exptectCalled: true,
expectModified: false,
},
{
name: "reject",
prefix: net.NewPfx(0, 0),
path: &route.Path{},
term: &Term{
then: []FilterAction{
&actions.RejectAction{},
},
},
exptectCalled: false,
expectModified: false,
},
{
name: "modified",
prefix: net.NewPfx(0, 0),
path: &route.Path{},
term: &Term{
then: []FilterAction{
&mockAction{},
&actions.AcceptAction{},
},
},
exptectCalled: true,
expectModified: true,
},
}
for _, test := range tests {
t.Run(test.name, func(te *testing.T) {
m := newClientMock()
f := NewFilter([]*Term{test.term})
f.Register(m)
import (
"testing"
f.AddPath(test.prefix, test.path)
assert.Equal(te, test.exptectCalled, m.addPathCalled, "called")
"github.com/bio-routing/bio-rd/net"
"github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable/filter/actions"
"github.com/stretchr/testify/assert"
)
if !test.exptectCalled {
return
}
if m.path != test.path && !test.expectModified {
te.Fatal("expected path to be not modified but was")
}
if m.path == test.path && test.expectModified {
te.Fatal("expected path to be modified but was same reference")
}
})
}
}
func TestRemovePath(t *testing.T) {
func TestProcessTerms(t *testing.T) {
tests := []struct {
name string
prefix net.Prefix
path *route.Path
term *Term
exptectCalled bool
exptectAccept bool
expectModified bool
}{
{
......@@ -91,7 +27,7 @@ func TestRemovePath(t *testing.T) {
&actions.AcceptAction{},
},
},
exptectCalled: true,
exptectAccept: true,
expectModified: false,
},
{
......@@ -103,7 +39,7 @@ func TestRemovePath(t *testing.T) {
&actions.RejectAction{},
},
},
exptectCalled: false,
exptectAccept: false,
expectModified: false,
},
{
......@@ -116,32 +52,21 @@ func TestRemovePath(t *testing.T) {
&actions.AcceptAction{},
},
},
exptectCalled: true,
exptectAccept: true,
expectModified: true,
},
}
for _, test := range tests {
t.Run(test.name, func(te *testing.T) {
m := newClientMock()
f := NewFilter([]*Term{test.term})
f.Register(m)
p, reject := f.ProcessTerms(test.prefix, test.path)
f.RemovePath(test.prefix, test.path)
assert.Equal(te, test.exptectCalled, m.removePathCalled, "called")
if !test.exptectCalled {
return
}
assert.Equal(t, test.exptectAccept, !reject)
if m.path != test.path && !test.expectModified {
te.Fatal("expected path to be not modified but was")
}
if m.path == test.path && test.expectModified {
te.Fatal("expected path to be modified but was same reference")
if test.expectModified {
assert.NotEqual(t, test.path, p)
}
})
}
}*/
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment