diff --git a/routingtable/contributing_asn_list_test.go b/routingtable/contributing_asn_list_test.go index efc3f2ae79d56ea51af4fba3eb9e10eaf91e4c03..6387b18bcca92c290bc724ed8d13032104d247fa 100644 --- a/routingtable/contributing_asn_list_test.go +++ b/routingtable/contributing_asn_list_test.go @@ -24,7 +24,7 @@ func TestFancy(t *testing.T) { { runCmd: func() { c.Add(41981) }, expect: func() bool { return c.IsContributingASN(41981) }, - msg: "AS41981 should be contributing", + msg: "AS41981 should be contributing.", }, { runCmd: func() { c.Remove(41981) }, @@ -36,30 +36,49 @@ func TestFancy(t *testing.T) { { runCmd: func() { c.Add(41981) }, expect: func() bool { return c.IsContributingASN(41981) }, - msg: "AS41981 should be contributing", + msg: "AS41981 should be contributing.", }, { runCmd: func() { c.Add(201701) }, expect: func() bool { return c.IsContributingASN(41981) }, - msg: "AS201701 should be contributing", + msg: "AS201701 should be contributing.", }, // Add AS41981 2nd time { runCmd: func() { c.Add(41981) }, expect: func() bool { return c.IsContributingASN(41981) }, - msg: "AS41981 should be still contributing", + msg: "AS41981 should be still contributing.", }, { runCmd: func() {}, expect: func() bool { return c.contributingASNs[0].asn == 41981 }, - msg: "AS41981 is first ASN in list", + msg: "AS41981 is first ASN in list.", }, { runCmd: func() { fmt.Printf("%+v", c.contributingASNs) }, expect: func() bool { return c.contributingASNs[0].count == 2 }, msg: "AS41981 should be present twice.", }, + + // Remove 2nd AS41981 + { + runCmd: func() { c.Remove(41981) }, + expect: func() bool { return c.IsContributingASN(41981) }, + msg: "AS41981 should still be contributing.", + }, + { + runCmd: func() {}, + expect: func() bool { return c.contributingASNs[0].count == 1 }, + msg: "S41981 should be present once.", + }, + + // Remove AS201701 + { + runCmd: func() { c.Remove(201701) }, + expect: func() bool { return !c.IsContributingASN(201701) }, + msg: "AS201701 shouldn't be contributing no more.", + }, } for i, test := range tests { diff --git a/routingtable/filter/filter_test.go b/routingtable/filter/filter_test.go index 2f4aace7637f30095d106520495d12a2d3ad9626..273e986d29dc4e25a6788bfb8f750e54bff6beb4 100644 --- a/routingtable/filter/filter_test.go +++ b/routingtable/filter/filter_test.go @@ -1,85 +1,21 @@ 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) } }) } -}*/ +} diff --git a/routingtable/filter/helper_test.go b/routingtable/filter/helper_test.go index 5d82727a9f2b5b5e0f692a980d9d7515ccd4c71d..19a444d4a5c8d656534cfb415f2b401a11ae4c57 100644 --- a/routingtable/filter/helper_test.go +++ b/routingtable/filter/helper_test.go @@ -1,27 +1,23 @@ package filter -/*func TestNewAcceptAllFilter(t *testing.T) { - f := NewAcceptAllFilter() +import ( + "testing" - m := &clientMock{} - f.Register(m) + "github.com/bio-routing/bio-rd/net" + "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 { - t.Fatalf("expected accepted, but was filtered") - } + _, reject := f.ProcessTerms(net.NewPfx(0, 0), &route.Path{}) + assert.Equal(t, false, reject) } func TestNewDrainFilter(t *testing.T) { f := NewDrainFilter() - m := &clientMock{} - f.Register(m) - - f.AddPath(net.NewPfx(0, 0), &route.Path{}) - - if m.addPathCalled { - t.Fatalf("expected filtered, but was accepted") - } -}*/ + _, reject := f.ProcessTerms(net.NewPfx(0, 0), &route.Path{}) + assert.Equal(t, true, reject) +}