1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-31 00:08:08 -04:00
v2fly/common/buf/writer_test.go
2017-02-15 22:51:01 +01:00

27 lines
544 B
Go

package buf_test
import (
"bytes"
"crypto/rand"
"testing"
. "v2ray.com/core/common/buf"
"v2ray.com/core/testing/assert"
)
func TestWriter(t *testing.T) {
assert := assert.On(t)
lb := New()
assert.Error(lb.AppendSupplier(ReadFrom(rand.Reader))).IsNil()
expectedBytes := append([]byte(nil), lb.Bytes()...)
writeBuffer := bytes.NewBuffer(make([]byte, 0, 1024*1024))
writer := NewWriter(NewBufferedWriter(writeBuffer))
err := writer.Write(lb)
assert.Error(err).IsNil()
assert.Bytes(expectedBytes).Equals(writeBuffer.Bytes())
}