diff --git a/header_test.go b/header_test.go index 3f36a8c..dd9267f 100644 --- a/header_test.go +++ b/header_test.go @@ -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