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

Function TestFSServeFileUncompressed

fs_fs_test.go:267–307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

265}
266
267func TestFSServeFileUncompressed(t *testing.T) {
268 t.Parallel()
269
270 var ctx RequestCtx
271 ctx.Init(&Request{}, nil, nil)
272
273 var resp Response
274
275 expectedBody, err := getFileContents("/fs.go")
276 if err != nil {
277 t.Fatalf("unexpected error: %v", err)
278 }
279
280 ctx.Request.SetRequestURI("http://foobar.com/baz")
281 ctx.Request.Header.Set(HeaderAcceptEncoding, "gzip, zstd, br, wompwomp")
282 ServeFileUncompressed(&ctx, "fs.go")
283
284 s := ctx.Response.String()
285 br := bufio.NewReader(bytes.NewBufferString(s))
286 if err = resp.Read(br); err != nil {
287 t.Fatalf("unexpected error: %v", err)
288 }
289 if resp.StatusCode() != StatusOK {
290 t.Fatalf("unexpected status code: %d. Expecting %d", resp.StatusCode(), StatusOK)
291 }
292
293 ce := resp.Header.ContentEncoding()
294 if len(ce) > 0 {
295 t.Fatalf("unexpected 'Content-Encoding': %q. Expecting \"\"", string(ce))
296 }
297
298 vary := resp.Header.PeekBytes(strVary)
299 if len(vary) > 0 {
300 t.Fatalf("unexpected 'Vary': %q. Expecting \"\"", string(vary))
301 }
302
303 body := resp.Body()
304 if !bytes.Equal(body, expectedBody) {
305 t.Fatalf("unexpected body: len=%d. Expecting len=%d", len(body), len(expectedBody))
306 }
307}
308
309func TestFSFSByteRangeConcurrent(t *testing.T) {
310 t.Parallel()

Callers

nothing calls this directly

Calls 12

InitMethod · 0.95
ReadMethod · 0.95
StatusCodeMethod · 0.95
BodyMethod · 0.95
getFileContentsFunction · 0.85
ServeFileUncompressedFunction · 0.85
NewReaderMethod · 0.80
SetRequestURIMethod · 0.45
SetMethod · 0.45
StringMethod · 0.45
ContentEncodingMethod · 0.45
PeekBytesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…