writer_test.go 584 B

1234567891011121314151617181920212223242526
  1. package io_test
  2. import (
  3. "bytes"
  4. "crypto/rand"
  5. "testing"
  6. "github.com/v2ray/v2ray-core/common/alloc"
  7. . "github.com/v2ray/v2ray-core/common/io"
  8. v2testing "github.com/v2ray/v2ray-core/testing"
  9. "github.com/v2ray/v2ray-core/testing/assert"
  10. )
  11. func TestAdaptiveWriter(t *testing.T) {
  12. v2testing.Current(t)
  13. lb := alloc.NewLargeBuffer()
  14. rand.Read(lb.Value)
  15. writeBuffer := make([]byte, 0, 1024*1024)
  16. writer := NewAdaptiveWriter(NewBufferedWriter(bytes.NewBuffer(writeBuffer)))
  17. err := writer.Write(lb)
  18. assert.Error(err).IsNil()
  19. assert.Bytes(lb.Bytes()).Equals(writeBuffer)
  20. }