Skip to content
Snippets Groups Projects
Commit d3997a2e authored by Oliver Herms's avatar Oliver Herms
Browse files

More tests

parent bcd9cf95
No related branches found
No related tags found
No related merge requests found
......@@ -62,12 +62,8 @@ func decodePeerUpNotification(buf *bytes.Buffer, ch *CommonHeader) (*PeerUpNotif
&p.Information,
}
err = decoder.Decode(buf, fields)
if err != nil {
return nil, err
}
fmt.Printf("%v\n", p.Information)
// This can not fail as p.Information has exactly the size of what is left in buf
decoder.Decode(buf, fields)
return p, nil
}
......@@ -85,7 +81,11 @@ func getOpenMsg(buf *bytes.Buffer) ([]byte, error) {
}
optParams := make([]byte, msg[OpenMsgMinLen-1])
_, err = buf.Read(optParams)
fields := []interface{}{
&optParams,
}
err = decoder.Decode(buf, fields)
if err != nil {
return nil, fmt.Errorf("Unable to read: %v", err)
}
......
......@@ -79,6 +79,54 @@ func TestDecodePeerUp(t *testing.T) {
},
},
},
{
name: "Full #2",
input: []byte{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
0, 100,
0, 200,
// OPEN Sent
4, // Version
1, 0, // ASN
2, 0, // Hold Time
100, 110, 120, 130, // BGP Identifier
5, // Opt Parm Len
1, 2, 3, 4, 5,
// OPEN Recv
4, // Version
1, 0, // ASN
2, 0, // Hold Time
100, 110, 120, 130, // BGP Identifier
0, // Opt Parm Len
},
ch: &CommonHeader{
MsgLength: 44,
},
wantFail: false,
expected: &PeerUpNotification{
LocalAddress: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
LocalPort: 100,
RemotePort: 200,
SentOpenMsg: []byte{
4, // Version
1, 0, // ASN
2, 0, // Hold Time
100, 110, 120, 130, // BGP Identifier
5, // Opt Parm Len
1, 2, 3, 4, 5,
},
ReceivedOpenMsg: []byte{
// OPEN Recv
4, // Version
1, 0, // ASN
2, 0, // Hold Time
100, 110, 120, 130, // BGP Identifier
0, // Opt Parm Len
},
},
},
{
name: "Incomplete #1",
input: []byte{
......@@ -107,6 +155,50 @@ func TestDecodePeerUp(t *testing.T) {
},
wantFail: true,
},
{
name: "Incomplete #3",
input: []byte{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
0, 100,
0, 200,
// OPEN Sent
4, // Version
1, 0, // ASN
2, 0, // Hold Time
},
ch: &CommonHeader{
MsgLength: 47,
},
wantFail: true,
},
{
name: "Incomplete #4",
input: []byte{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
0, 100,
0, 200,
// OPEN Sent
4, // Version
1, 0, // ASN
2, 0, // Hold Time
100, 110, 120, 130, // BGP Identifier
5, // Opt Parm Len
1, 2, 3, 4, 5,
// OPEN Recv
4, // Version
1, 0, // ASN
2, 0, // Hold Time
100, 110, 120, 130, // BGP Identifier
3, // Opt Parm Len
},
ch: &CommonHeader{
MsgLength: 47,
},
wantFail: true,
},
}
for _, test := range tests {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment