v2ray-core/common/io/writer_test.go

28 lines
563 B
Go
Raw Normal View History

2016-05-11 10:54:20 -07:00
package io_test
import (
"bytes"
"crypto/rand"
"testing"
2016-08-20 20:55:45 +02:00
"v2ray.com/core/common/alloc"
. "v2ray.com/core/common/io"
"v2ray.com/core/testing/assert"
2016-05-11 10:54:20 -07:00
)
func TestAdaptiveWriter(t *testing.T) {
2016-05-24 21:55:46 +02:00
assert := assert.On(t)
2016-05-11 10:54:20 -07:00
2016-12-06 11:03:42 +01:00
lb := alloc.NewBuffer()
2016-12-05 15:19:14 +01:00
lb.FillFrom(rand.Reader)
2016-05-11 10:54:20 -07:00
2016-12-06 11:03:42 +01:00
expectedBytes := append([]byte(nil), lb.Bytes()...)
2016-05-11 10:54:20 -07:00
2016-12-06 11:03:42 +01:00
writeBuffer := bytes.NewBuffer(make([]byte, 0, 1024*1024))
writer := NewAdaptiveWriter(NewBufferedWriter(writeBuffer))
2016-05-11 10:54:20 -07:00
err := writer.Write(lb)
assert.Error(err).IsNil()
2016-12-06 11:03:42 +01:00
assert.Bytes(expectedBytes).Equals(writeBuffer.Bytes())
2016-05-11 10:54:20 -07:00
}