1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 23:36:25 -04:00
v2fly/common/io/writer_test.go
2016-12-06 11:03:42 +01:00

28 lines
563 B
Go

package io_test
import (
"bytes"
"crypto/rand"
"testing"
"v2ray.com/core/common/alloc"
. "v2ray.com/core/common/io"
"v2ray.com/core/testing/assert"
)
func TestAdaptiveWriter(t *testing.T) {
assert := assert.On(t)
lb := alloc.NewBuffer()
lb.FillFrom(rand.Reader)
expectedBytes := append([]byte(nil), lb.Bytes()...)
writeBuffer := bytes.NewBuffer(make([]byte, 0, 1024*1024))
writer := NewAdaptiveWriter(NewBufferedWriter(writeBuffer))
err := writer.Write(lb)
assert.Error(err).IsNil()
assert.Bytes(expectedBytes).Equals(writeBuffer.Bytes())
}