mirror of https://github.com/v2ray/v2ray-core
fix test read buf
parent
45398c2bc9
commit
c060f9f11f
|
@ -7,6 +7,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
"github.com/google/go-cmp/cmp"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
. "v2ray.com/core/common/buf"
|
. "v2ray.com/core/common/buf"
|
||||||
|
@ -98,6 +100,7 @@ func TestMultiBufferSplitFirst(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiBufferReadAllToByte(t *testing.T) {
|
func TestMultiBufferReadAllToByte(t *testing.T) {
|
||||||
|
{
|
||||||
lb := make([]byte, 8*1024)
|
lb := make([]byte, 8*1024)
|
||||||
common.Must2(io.ReadFull(rand.Reader, lb))
|
common.Must2(io.ReadFull(rand.Reader, lb))
|
||||||
rd := bytes.NewBuffer(lb)
|
rd := bytes.NewBuffer(lb)
|
||||||
|
@ -107,6 +110,24 @@ func TestMultiBufferReadAllToByte(t *testing.T) {
|
||||||
if l := len(b); l != 8*1024 {
|
if l := len(b); l != 8*1024 {
|
||||||
t.Error("unexpceted length from ReadAllToBytes", l)
|
t.Error("unexpceted length from ReadAllToBytes", l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const dat = "data/test_MultiBufferReadAllToByte.dat"
|
||||||
|
f, err := os.Open(dat)
|
||||||
|
common.Must(err)
|
||||||
|
|
||||||
|
buf2, err := ReadAllToBytes(f)
|
||||||
|
common.Must(err)
|
||||||
|
f.Close()
|
||||||
|
|
||||||
|
cnt, err := ioutil.ReadFile(dat)
|
||||||
|
common.Must(err)
|
||||||
|
|
||||||
|
if d := cmp.Diff(buf2, cnt); d != "" {
|
||||||
|
t.Error("fail to read from file: ", d)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMultiBufferCopy(t *testing.T) {
|
func TestMultiBufferCopy(t *testing.T) {
|
||||||
|
|
|
@ -3,12 +3,9 @@ package buf_test
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
. "v2ray.com/core/common/buf"
|
. "v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/transport/pipe"
|
"v2ray.com/core/transport/pipe"
|
||||||
|
@ -92,23 +89,6 @@ func TestReadBuffer(t *testing.T) {
|
||||||
buf.Release()
|
buf.Release()
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
const dat = "data/test_ReadBuffer.dat"
|
|
||||||
f, err := os.Open(dat)
|
|
||||||
common.Must(err)
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
buf2, err := ReadBuffer(f)
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
cnt, err := ioutil.ReadFile(dat)
|
|
||||||
common.Must(err)
|
|
||||||
|
|
||||||
if cmp.Diff(buf2.Bytes(), cnt) != "" {
|
|
||||||
t.Error("fail to read from file")
|
|
||||||
}
|
|
||||||
buf2.Release()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadAtMost(t *testing.T) {
|
func TestReadAtMost(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue