MCPcopy Create free account
hub / github.com/gavv/httpexpect / TestFastBinder_Chunked

Function TestFastBinder_Chunked

binder_test.go:404–458  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

402}
403
404func TestFastBinder_Chunked(t *testing.T) {
405 handler := func(ctx *fasthttp.RequestCtx) {
406 assert.Equal(t, "POST", string(ctx.Request.Header.Method()))
407 assert.Equal(t, "http://example.com/path", string(ctx.Request.Header.RequestURI()))
408
409 assert.Equal(t, "application/x-www-form-urlencoded",
410 string(ctx.Request.Header.ContentType()))
411
412 headers := map[string][]string{}
413
414 ctx.Request.Header.VisitAll(func(k, v []byte) {
415 headers[string(k)] = append(headers[string(k)], string(v))
416 })
417
418 expected := map[string][]string{
419 "Host": {"example.com"},
420 "Content-Type": {"application/x-www-form-urlencoded"},
421 "Transfer-Encoding": {"chunked"},
422 }
423
424 assert.Equal(t, expected, headers)
425
426 assert.Equal(t, "bar", string(ctx.FormValue("foo")))
427 assert.Equal(t, "foo=bar", string(ctx.Request.Body()))
428
429 ctx.Response.Header.Set("Content-Type", "application/json")
430 ctx.Response.SetBodyStreamWriter(func(w *bufio.Writer) {
431 _, _ = w.WriteString(`[1, `)
432 _ = w.Flush()
433 _, _ = w.WriteString(`2]`)
434 })
435 }
436
437 client := &http.Client{
438 Transport: NewFastBinder(handler),
439 }
440
441 req, err := http.NewRequest(
442 "POST", "http://example.com/path", strings.NewReader("foo=bar"))
443
444 if err != nil {
445 t.Fatal(err)
446 }
447
448 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
449
450 req.ContentLength = -1
451
452 resp, err := client.Do(req)
453 if err != nil {
454 t.Fatal(err)
455 }
456
457 assert.Equal(t, []string{"chunked"}, resp.TransferEncoding)
458}
459
460func TestFastBinder_EmptyResponse(t *testing.T) {
461 handler := func(*fasthttp.RequestCtx) {}

Callers

nothing calls this directly

Calls 6

DoMethod · 0.95
NewFastBinderFunction · 0.85
ContentTypeMethod · 0.80
NewRequestMethod · 0.65
EqualMethod · 0.45
BodyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…