| Index: common/recordio/reader_test.go
|
| diff --git a/common/recordio/reader_test.go b/common/recordio/reader_test.go
|
| index 74f2f41aef5f1ae348e3c79c005bbe8580926d44..5e4744c73d003780f91a32b6dc6f681fd28fa21c 100644
|
| --- a/common/recordio/reader_test.go
|
| +++ b/common/recordio/reader_test.go
|
| @@ -8,6 +8,7 @@ import (
|
| "bytes"
|
| "encoding/binary"
|
| "errors"
|
| + "fmt"
|
| "io"
|
| "io/ioutil"
|
| "testing"
|
| @@ -58,6 +59,14 @@ func (r *testByteReader) ReadByte() (b byte, err error) {
|
| return
|
| }
|
|
|
| +func btos(b ...[]byte) []string {
|
| + s := make([]string, len(b))
|
| + for i, v := range b {
|
| + s[i] = string(v)
|
| + }
|
| + return s
|
| +}
|
| +
|
| // TestReader tests the default Reader implementation, "reader".
|
| func TestReader(t *testing.T) {
|
| t.Parallel()
|
| @@ -205,3 +214,43 @@ func TestReader(t *testing.T) {
|
| })
|
| })
|
| }
|
| +
|
| +func TestSplit(t *testing.T) {
|
| + t.Parallel()
|
| +
|
| + Convey(`Testing Split`, t, func() {
|
| + for _, v := range [][]string{
|
| + {},
|
| + {""},
|
| + {"", "foo", ""},
|
| + {"foo", "bar", "baz"},
|
| + } {
|
| + Convey(fmt.Sprintf(`Can Split stream: %#v`, v), func() {
|
| + // Write frames to "buf".
|
| + var buf bytes.Buffer
|
| + for _, s := range v {
|
| + _, err := WriteFrame(&buf, []byte(s))
|
| + if err != nil {
|
| + panic(err)
|
| + }
|
| + }
|
| +
|
| + // Confirm that Split works.
|
| + sp, err := Split(buf.Bytes())
|
| + So(err, ShouldBeNil)
|
| + So(btos(sp...), ShouldResemble, v)
|
| + })
|
| + }
|
| +
|
| + Convey(`Will refuse to split a frame that is too large.`, func() {
|
| + _, err := Split([]byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00})
|
| + So(err, ShouldEqual, ErrFrameTooLarge)
|
| + })
|
| +
|
| + Convey(`Will fail to split if there aren't enough bytes.`, func() {
|
| + sp, err := Split([]byte{0x01, 0xAA, 0x02}) // 1-byte {0xAA}, 2-bytes ... EOF!
|
| + So(sp, ShouldResemble, [][]byte{{0xAA}})
|
| + So(err, ShouldEqual, ErrFrameTooLarge)
|
| + })
|
| + })
|
| +}
|
|
|