mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
537 B
26 lines
537 B
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) {
|
|
assert := assert.On(t)
|
|
|
|
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)
|
|
}
|