1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-18 02:16:10 -05:00
v2fly/common/buf/buffered_reader_test.go
Darien Raymond 6c9a60100d format code
2017-10-26 21:44:22 +02:00

37 lines
653 B
Go

package buf_test
import (
"crypto/rand"
"testing"
. "v2ray.com/core/common/buf"
. "v2ray.com/ext/assert"
)
func TestBufferedReader(t *testing.T) {
assert := With(t)
content := New()
assert(content.AppendSupplier(ReadFrom(rand.Reader)), IsNil)
len := content.Len()
reader := NewBufferedReader(content)
assert(reader.IsBuffered(), IsTrue)
payload := make([]byte, 16)
nBytes, err := reader.Read(payload)
assert(nBytes, Equals, 16)
assert(err, IsNil)
len2 := content.Len()
assert(len-len2, GreaterThan, 16)
nBytes, err = reader.Read(payload)
assert(nBytes, Equals, 16)
assert(err, IsNil)
assert(content.Len(), Equals, len2)
}