mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-16 09:26:21 -05:00
28 lines
573 B
Go
28 lines
573 B
Go
package buf_test
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"testing"
|
|
|
|
. "v2ray.com/core/common/buf"
|
|
"v2ray.com/core/common/bufio"
|
|
"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(bufio.NewWriter(writeBuffer))
|
|
err := writer.Write(lb)
|
|
assert.Error(err).IsNil()
|
|
assert.Bytes(expectedBytes).Equals(writeBuffer.Bytes())
|
|
}
|