From bfce0fa31c455f52ceb908dbd30e2d86c44ab6fc Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 12 Feb 2016 14:15:28 +0200 Subject: [PATCH] substituted bytes.Buffer by ByteBuffer in tests where appropriate --- args_test.go | 5 ++--- bytesconv_test.go | 4 ++-- http_test.go | 18 +++++++++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/args_test.go b/args_test.go index e238272..e677677 100644 --- a/args_test.go +++ b/args_test.go @@ -1,7 +1,6 @@ package fasthttp import ( - "bytes" "fmt" "strings" "testing" @@ -28,7 +27,7 @@ func TestArgsWriteTo(t *testing.T) { var a Args a.Parse(s) - var w bytes.Buffer + var w ByteBuffer n, err := a.WriteTo(&w) if err != nil { t.Fatalf("unexpected error: %s", err) @@ -36,7 +35,7 @@ func TestArgsWriteTo(t *testing.T) { if n != int64(len(s)) { t.Fatalf("unexpected n: %d. Expecting %d", n, len(s)) } - result := string(w.Bytes()) + result := string(w.B) if result != s { t.Fatalf("unexpected result %q. Expecting %q", result, s) } diff --git a/bytesconv_test.go b/bytesconv_test.go index 24458db..83eb3d8 100644 --- a/bytesconv_test.go +++ b/bytesconv_test.go @@ -77,7 +77,7 @@ func testAppendUint(t *testing.T, n int) { } func testWriteHexInt(t *testing.T, n int, expectedS string) { - var w bytes.Buffer + var w ByteBuffer bw := bufio.NewWriter(&w) if err := writeHexInt(bw, n); err != nil { t.Fatalf("unexpected error when writing hex %x: %s", n, err) @@ -85,7 +85,7 @@ func testWriteHexInt(t *testing.T, n int, expectedS string) { if err := bw.Flush(); err != nil { t.Fatalf("unexpected error when flushing hex %x: %s", n, err) } - s := string(w.Bytes()) + s := string(w.B) if s != expectedS { t.Fatalf("unexpected hex after writing %q. Expected %q", s, expectedS) } diff --git a/http_test.go b/http_test.go index dff62b8..4a4c556 100644 --- a/http_test.go +++ b/http_test.go @@ -59,12 +59,12 @@ type bodyWriterTo interface { } func testBodyWriteTo(t *testing.T, bw bodyWriterTo, expectedS string, isRetainedBody bool) { - var buf bytes.Buffer + var buf ByteBuffer if err := bw.BodyWriteTo(&buf); err != nil { t.Fatalf("unexpected error: %s", err) } - s := buf.Bytes() + s := buf.B if string(s) != expectedS { t.Fatalf("unexpected result %q. Expecting %q", s, expectedS) } @@ -133,7 +133,7 @@ func TestResponseWriteTo(t *testing.T) { r.SetBodyString("foobar") s := r.String() - var buf bytes.Buffer + var buf ByteBuffer n, err := r.WriteTo(&buf) if err != nil { t.Fatalf("unexpected error: %s", err) @@ -141,8 +141,8 @@ func TestResponseWriteTo(t *testing.T) { if n != int64(len(s)) { t.Fatalf("unexpected response length %d. Expecting %d", n, len(s)) } - if string(buf.Bytes()) != s { - t.Fatalf("unexpected response %q. Expecting %q", buf.Bytes(), s) + if string(buf.B) != s { + t.Fatalf("unexpected response %q. Expecting %q", buf.B, s) } } @@ -152,7 +152,7 @@ func TestRequestWriteTo(t *testing.T) { r.SetRequestURI("http://foobar.com/aaa/bbb") s := r.String() - var buf bytes.Buffer + var buf ByteBuffer n, err := r.WriteTo(&buf) if err != nil { t.Fatalf("unexpected error: %s", err) @@ -160,8 +160,8 @@ func TestRequestWriteTo(t *testing.T) { if n != int64(len(s)) { t.Fatalf("unexpected request length %d. Expecting %d", n, len(s)) } - if string(buf.Bytes()) != s { - t.Fatalf("unexpected request %q. Expecting %q", buf.Bytes(), s) + if string(buf.B) != s { + t.Fatalf("unexpected request %q. Expecting %q", buf.B, s) } } @@ -891,7 +891,7 @@ func testRequestWriteError(t *testing.T, method, requestURI, host, userAgent, bo req.Header.Set("User-Agent", userAgent) req.SetBody([]byte(body)) - w := &bytes.Buffer{} + w := &ByteBuffer{} bw := bufio.NewWriter(w) err := req.Write(bw) if err == nil {