Skip to content
Snippets Groups Projects
Unverified Commit cfcf9c8c authored by takt's avatar takt Committed by GitHub
Browse files

Merge pull request #68 from bio-routing/fix/filter_tests

Fix/filter tests
parents 0d2c721d 80ad835f
Branches
Tags
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")
} }
}) })
} }
}*/ }
package filter package filter
/*func TestNewAcceptAllFilter(t *testing.T) { import (
f := NewAcceptAllFilter() "testing"
m := &clientMock{} "github.com/bio-routing/bio-rd/net"
f.Register(m) "github.com/bio-routing/bio-rd/route"
"github.com/stretchr/testify/assert"
)
f.AddPath(net.NewPfx(0, 0), &route.Path{}) func TestNewAcceptAllFilter(t *testing.T) {
f := NewAcceptAllFilter()
if !m.addPathCalled { _, reject := f.ProcessTerms(net.NewPfx(0, 0), &route.Path{})
t.Fatalf("expected accepted, but was filtered") assert.Equal(t, false, reject)
}
} }
func TestNewDrainFilter(t *testing.T) { func TestNewDrainFilter(t *testing.T) {
f := NewDrainFilter() f := NewDrainFilter()
m := &clientMock{} _, reject := f.ProcessTerms(net.NewPfx(0, 0), &route.Path{})
f.Register(m) assert.Equal(t, true, reject)
}
f.AddPath(net.NewPfx(0, 0), &route.Path{})
if m.addPathCalled {
t.Fatalf("expected filtered, but was accepted")
}
}*/
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment