mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-15 16:07:51 +03:00
substituted bytes.Buffer by ByteBuffer in tests where appropriate
This commit is contained in:
+2
-3
@@ -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)
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
|
||||
+9
-9
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user