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 package filter
/*func TestAddPath(t *testing.T) { import (
tests := []struct { "testing"
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)
f.AddPath(test.prefix, test.path) "github.com/bio-routing/bio-rd/net"
assert.Equal(te, test.exptectCalled, m.addPathCalled, "called") "github.com/bio-routing/bio-rd/route"
"github.com/bio-routing/bio-rd/routingtable/filter/actions"
"github.com/stretchr/testify/assert"
)
if !test.exptectCalled { func TestProcessTerms(t *testing.T) {
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) {
tests := []struct { tests := []struct {
name string name string
prefix net.Prefix prefix net.Prefix
path *route.Path path *route.Path
term *Term term *Term
exptectCalled bool exptectAccept bool
expectModified bool expectModified bool
}{ }{
{ {
...@@ -91,7 +27,7 @@ func TestRemovePath(t *testing.T) { ...@@ -91,7 +27,7 @@ func TestRemovePath(t *testing.T) {
&actions.AcceptAction{}, &actions.AcceptAction{},
}, },
}, },
exptectCalled: true, exptectAccept: true,
expectModified: false, expectModified: false,
}, },
{ {
...@@ -103,7 +39,7 @@ func TestRemovePath(t *testing.T) { ...@@ -103,7 +39,7 @@ func TestRemovePath(t *testing.T) {
&actions.RejectAction{}, &actions.RejectAction{},
}, },
}, },
exptectCalled: false, exptectAccept: false,
expectModified: false, expectModified: false,
}, },
{ {
...@@ -116,32 +52,21 @@ func TestRemovePath(t *testing.T) { ...@@ -116,32 +52,21 @@ func TestRemovePath(t *testing.T) {
&actions.AcceptAction{}, &actions.AcceptAction{},
}, },
}, },
exptectCalled: true, exptectAccept: true,
expectModified: true, expectModified: true,
}, },
} }
for _, test := range tests { for _, test := range tests {
t.Run(test.name, func(te *testing.T) { t.Run(test.name, func(te *testing.T) {
m := newClientMock()
f := NewFilter([]*Term{test.term}) f := NewFilter([]*Term{test.term})
f.Register(m) p, reject := f.ProcessTerms(test.prefix, test.path)
f.RemovePath(test.prefix, test.path) assert.Equal(t, test.exptectAccept, !reject)
assert.Equal(te, test.exptectCalled, m.removePathCalled, "called")
if !test.exptectCalled {
return
}
if m.path != test.path && !test.expectModified { if test.expectModified {
te.Fatal("expected path to be not modified but was") assert.NotEqual(t, test.path, p)
}
if m.path == test.path && test.expectModified {
te.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