Skip to content

Commit

Permalink
substituted bytes.Buffer by ByteBuffer in tests where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
valyala committed Feb 12, 2016
1 parent 80368e6 commit bfce0fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions args_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package fasthttp

import (
"bytes"
"fmt"
"strings"
"testing"
Expand All @@ -28,15 +27,15 @@ 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)
}
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)
}
Expand Down
4 changes: 2 additions & 2 deletions bytesconv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ 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)
}
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)
}
Expand Down
18 changes: 9 additions & 9 deletions http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -133,16 +133,16 @@ 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)
}
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)
}
}

Expand All @@ -152,16 +152,16 @@ 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)
}
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)
}
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bfce0fa

Please sign in to comment.