MCPcopy
hub / github.com/valyala/fasthttp / testResponseBodyStreamGzip

Function testResponseBodyStreamGzip

http_test.go:361–393  ·  view source on GitHub ↗
(t *testing.T, body []byte, bodySize int)

Source from the content-addressed store, hash-verified

359}
360
361func testResponseBodyStreamGzip(t *testing.T, body []byte, bodySize int) {
362 var r Response
363 r.SetBodyStream(bytes.NewReader(body), bodySize)
364
365 w := &bytes.Buffer{}
366 bw := bufio.NewWriter(w)
367 if err := r.WriteGzip(bw); err != nil {
368 t.Fatalf("unexpected error: %v", err)
369 }
370 if err := bw.Flush(); err != nil {
371 t.Fatalf("unexpected error: %v", err)
372 }
373
374 var resp Response
375 br := bufio.NewReader(w)
376 if err := resp.Read(br); err != nil {
377 t.Fatalf("unexpected error: %v", err)
378 }
379
380 respBody, err := resp.BodyGunzip()
381 if err != nil {
382 t.Fatalf("unexpected error: %v", err)
383 }
384 if !bytes.Equal(respBody, body) {
385 t.Fatalf("unexpected body: %q. Expecting %q", respBody, body)
386 }
387 // check for invalid
388 resp.SetBodyRaw([]byte("invalid"))
389 _, errUnzip := resp.BodyGunzip()
390 if errUnzip == nil || errUnzip.Error() != "unexpected EOF" {
391 t.Fatalf("expected error: 'unexpected EOF' but was %v", errUnzip)
392 }
393}
394
395func TestResponseWriteGzipNilBody(t *testing.T) {
396 t.Parallel()

Callers 1

Calls 8

SetBodyStreamMethod · 0.95
WriteGzipMethod · 0.95
FlushMethod · 0.95
ReadMethod · 0.95
BodyGunzipMethod · 0.95
SetBodyRawMethod · 0.95
NewReaderMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…