Skip to content

Commit

Permalink
fix test read buf
Browse files Browse the repository at this point in the history
  • Loading branch information
vcptr committed Nov 27, 2019
1 parent 45398c2 commit c060f9f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
File renamed without changes.
35 changes: 28 additions & 7 deletions common/buf/multi_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"io/ioutil"
"os"

"v2ray.com/core/common"
. "v2ray.com/core/common/buf"
Expand Down Expand Up @@ -98,14 +100,33 @@ func TestMultiBufferSplitFirst(t *testing.T) {
}

func TestMultiBufferReadAllToByte(t *testing.T) {
lb := make([]byte, 8*1024)
common.Must2(io.ReadFull(rand.Reader, lb))
rd := bytes.NewBuffer(lb)
b, err := ReadAllToBytes(rd)
common.Must(err)
{
lb := make([]byte, 8*1024)
common.Must2(io.ReadFull(rand.Reader, lb))
rd := bytes.NewBuffer(lb)
b, err := ReadAllToBytes(rd)
common.Must(err)

if l := len(b); l != 8*1024 {
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 l := len(b); l != 8*1024 {
t.Error("unexpceted length from ReadAllToBytes", l)
if d := cmp.Diff(buf2, cnt); d != "" {
t.Error("fail to read from file: ", d)
}
}
}

Expand Down
20 changes: 0 additions & 20 deletions common/buf/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ package buf_test
import (
"bytes"
"io"
"io/ioutil"
"os"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"v2ray.com/core/common"
. "v2ray.com/core/common/buf"
"v2ray.com/core/transport/pipe"
Expand Down Expand Up @@ -92,23 +89,6 @@ func TestReadBuffer(t *testing.T) {
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) {
Expand Down

0 comments on commit c060f9f

Please sign in to comment.