diff options
author | dsp <dsp@2f30.org> | 2015-07-25 09:20:26 -0600 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-26 21:30:26 +0900 |
commit | b5c44231b31460f6291cec2f3aafe913bf0d0037 (patch) | |
tree | ca51d1cbf1432188e622d709db55cb816cab4de3 /packet/mrt_test.go | |
parent | bcf1314bf6e9a082c4eb7b709b83cd91b00f3ed0 (diff) |
packet: mrt: commiting support and test for a split function for use in MRT messages under the bufio interface
Diffstat (limited to 'packet/mrt_test.go')
-rw-r--r-- | packet/mrt_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/packet/mrt_test.go b/packet/mrt_test.go index 7aa073c4..c43d45e0 100644 --- a/packet/mrt_test.go +++ b/packet/mrt_test.go @@ -16,6 +16,8 @@ package bgp import ( + "bufio" + "bytes" "github.com/stretchr/testify/assert" "reflect" "testing" @@ -181,3 +183,27 @@ func TestMrtBgp4mpMessage(t *testing.T) { } assert.Equal(t, reflect.DeepEqual(m1, m2), true) } + +func TestMrtSplit(t *testing.T) { + var b bytes.Buffer + numwrite, numread := 10, 0 + for i := 0; i < numwrite; i++ { + msg := NewBGPKeepAliveMessage() + m1 := NewBGP4MPMessage(65000, 65001, 1, "192.168.0.1", "192.168.0.2", false, msg) + mm, _ := NewMRTMessage(1234, BGP4MP, MESSAGE, m1) + b1, err := mm.Serialize() + if err != nil { + t.Fatal(err) + } + b.Write(b1) + } + t.Logf("wrote %d serialized MRT keepalives in the buffer", numwrite) + r := bytes.NewReader(b.Bytes()) + scanner := bufio.NewScanner(r) + scanner.Split(SplitMrt) + for scanner.Scan() { + numread += 1 + } + t.Logf("scanner scanned %d serialized keepalives from the buffer", numread) + assert.Equal(t, numwrite, numread) +} |