From b5c44231b31460f6291cec2f3aafe913bf0d0037 Mon Sep 17 00:00:00 2001 From: dsp Date: Sat, 25 Jul 2015 09:20:26 -0600 Subject: packet: mrt: commiting support and test for a split function for use in MRT messages under the bufio interface --- packet/mrt_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'packet/mrt_test.go') 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) +} -- cgit v1.2.3