Added a test for bufferStartEnd

This commit is contained in:
Aliaksandr Valialkin
2016-02-18 16:21:04 +02:00
parent 714b45e4c7
commit d95ef5ab6c
+29
View File
@@ -10,6 +10,35 @@ import (
"testing"
)
func TestBufferStartEnd(t *testing.T) {
testBufferStartEnd(t, "", "", "")
testBufferStartEnd(t, "foobar", "foobar", "")
b := string(createFixedBody(199))
testBufferStartEnd(t, b, b, "")
for i := 0; i < 10; i++ {
b += "foobar"
testBufferStartEnd(t, b, b, "")
}
b = string(createFixedBody(400))
testBufferStartEnd(t, b, b, "")
for i := 0; i < 10; i++ {
b += "sadfqwer"
testBufferStartEnd(t, b, b[:200], b[len(b)-200:])
}
}
func testBufferStartEnd(t *testing.T, buf, expectedStart, expectedEnd string) {
start, end := bufferStartEnd([]byte(buf))
if string(start) != expectedStart {
t.Fatalf("unexpected start %q. Expecting %q. buf %q", start, expectedStart, buf)
}
if string(end) != expectedEnd {
t.Fatalf("unexpected end %q. Expecting %q. buf %q", end, expectedEnd, buf)
}
}
func TestResponseHeaderTrailingCRLFSuccess(t *testing.T) {
trailingCRLF := "\r\n\r\n\r\n"
s := "HTTP/1.1 200 OK\r\nContent-Type: aa\r\nContent-Length: 123\r\n\r\n" + trailingCRLF