Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
59fbc525
Commit
59fbc525
authored
6 years ago
by
Christoph Petrausch
Browse files
Options
Downloads
Patches
Plain Diff
Added more testcases
parent
6e7b27cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
protocols/bgp/server/update_helper_test.go
+53
-3
53 additions, 3 deletions
protocols/bgp/server/update_helper_test.go
with
53 additions
and
3 deletions
protocols/bgp/server/update_helper_test.go
+
53
−
3
View file @
59fbc525
package
server
import
(
"io"
"testing"
"bytes"
"github.com/bio-routing/bio-rd/protocols/bgp/packet"
"errors"
"github.com/bio-routing/bio-rd/net"
"github.com/stretchr/testify/assert"
)
type
failingUpdate
struct
{}
func
(
f
*
failingUpdate
)
SerializeUpdate
()
([]
byte
,
error
)
{
return
nil
,
errors
.
New
(
"general error"
)
}
type
WriterByter
interface
{
Bytes
()
[]
byte
io
.
Writer
}
type
failingReadWriter
struct
{
}
func
(
f
*
failingReadWriter
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
return
0
,
errors
.
New
(
"general error"
)
}
func
(
f
*
failingReadWriter
)
Bytes
()
[]
byte
{
return
[]
byte
{}
}
func
TestSerializeAndSendUpdate
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
buf
WriterByter
err
error
testUpdate
serializeAbleUpdate
expected
[]
byte
}{
{
name
:
"normal bgp update"
,
buf
:
bytes
.
NewBuffer
(
nil
),
err
:
nil
,
testUpdate
:
&
packet
.
BGPUpdate
{
WithdrawnRoutesLen
:
5
,
...
...
@@ -40,14 +67,37 @@ func TestSerializeAndSendUpdate(t *testing.T) {
0
,
5
,
8
,
10
,
16
,
192
,
168
,
0
,
0
,
// 2 withdraws
},
},
{
name
:
"failed serialization"
,
buf
:
bytes
.
NewBuffer
(
nil
),
err
:
nil
,
testUpdate
:
&
failingUpdate
{},
expected
:
nil
,
},
{
name
:
"failed connection"
,
buf
:
&
failingReadWriter
{},
err
:
errors
.
New
(
"Failed sending Update: general error"
),
testUpdate
:
&
packet
.
BGPUpdate
{
WithdrawnRoutesLen
:
5
,
WithdrawnRoutes
:
&
packet
.
NLRI
{
IP
:
strAddr
(
"10.0.0.0"
),
Pfxlen
:
8
,
Next
:
&
packet
.
NLRI
{
IP
:
strAddr
(
"192.168.0.0"
),
Pfxlen
:
16
,
},
},
},
expected
:
[]
byte
{},
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
buf
:=
bytes
.
NewBuffer
(
nil
)
err
:=
serializeAndSendUpdate
(
buf
,
test
.
testUpdate
)
err
:=
serializeAndSendUpdate
(
test
.
buf
,
test
.
testUpdate
)
assert
.
Equal
(
t
,
test
.
err
,
err
)
assert
.
Equal
(
t
,
test
.
expected
,
buf
.
Bytes
())
assert
.
Equal
(
t
,
test
.
expected
,
test
.
buf
.
Bytes
())
})
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment