v2ray-core/common/io/writer_test.go

26 lines
537 B
Go
Raw Normal View History

2016-05-11 17:54:20 +00:00
package io_test
import (
"bytes"
"crypto/rand"
"testing"
"github.com/v2ray/v2ray-core/common/alloc"
. "github.com/v2ray/v2ray-core/common/io"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestAdaptiveWriter(t *testing.T) {
2016-05-24 19:55:46 +00:00
assert := assert.On(t)
2016-05-11 17:54:20 +00:00
lb := alloc.NewLargeBuffer()
rand.Read(lb.Value)
writeBuffer := make([]byte, 0, 1024*1024)
writer := NewAdaptiveWriter(NewBufferedWriter(bytes.NewBuffer(writeBuffer)))
err := writer.Write(lb)
assert.Error(err).IsNil()
assert.Bytes(lb.Bytes()).Equals(writeBuffer)
}