MCPcopy
hub / github.com/gofiber/fiber / Test_Ctx_BodyStreamWriter

Function Test_Ctx_BodyStreamWriter

ctx_test.go:8806–8828  ·  view source on GitHub ↗

go test -run Test_Ctx_BodyStreamWriter

(t *testing.T)

Source from the content-addressed store, hash-verified

8804
8805// go test -run Test_Ctx_BodyStreamWriter
8806func Test_Ctx_BodyStreamWriter(t *testing.T) {
8807 t.Parallel()
8808 ctx := &fasthttp.RequestCtx{}
8809
8810 ctx.SetBodyStreamWriter(func(w *bufio.Writer) {
8811 fmt.Fprintf(w, "body writer line 1\n")
8812 if err := w.Flush(); err != nil {
8813 t.Errorf("unexpected error: %s", err)
8814 }
8815 fmt.Fprintf(w, "body writer line 2\n")
8816 })
8817
8818 require.True(t, ctx.IsBodyStream())
8819
8820 s := ctx.Response.String()
8821 br := bufio.NewReader(bytes.NewBufferString(s))
8822 var resp fasthttp.Response
8823 require.NoError(t, resp.Read(br))
8824
8825 body := string(resp.Body())
8826 expectedBody := "body writer line 1\nbody writer line 2\n"
8827 require.Equal(t, expectedBody, body)
8828}
8829
8830// go test -v -run=^$ -bench=Benchmark_Ctx_BodyStreamWriter -benchmem -count=4
8831func Benchmark_Ctx_BodyStreamWriter(b *testing.B) {

Callers

nothing calls this directly

Calls 5

BodyMethod · 0.95
ErrorfMethod · 0.65
StringMethod · 0.65
FlushMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected