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

Function Test_FiberHandler_WithSendStreamWriter

middleware/adaptor/adaptor_test.go:1054–1082  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1052}
1053
1054func Test_FiberHandler_WithSendStreamWriter(t *testing.T) {
1055 t.Parallel()
1056
1057 // Test streaming functionality in FiberHandler using SendStreamWriter.
1058 fiberH := func(c fiber.Ctx) error {
1059 c.Status(fiber.StatusTeapot)
1060 return c.SendStreamWriter(func(w *bufio.Writer) {
1061 w.WriteString("Hello ") //nolint:errcheck // not needed
1062 w.Flush() //nolint:errcheck // not needed
1063 time.Sleep(200 * time.Millisecond) // Simulate a long operation
1064 w.WriteString("World!") //nolint:errcheck // not needed
1065 })
1066 }
1067 handlerFunc := FiberHandlerFunc(fiberH)
1068
1069 r := &http.Request{
1070 Method: http.MethodGet,
1071 RequestURI: "/test",
1072 Header: make(http.Header),
1073 Body: http.NoBody,
1074 }
1075
1076 w := &netHTTPResponseWriter{}
1077 handlerFunc.ServeHTTP(w, r)
1078
1079 // Should return the error status
1080 require.Equal(t, fiber.StatusTeapot, w.StatusCode())
1081 require.Equal(t, "Hello World!", string(w.body))
1082}
1083
1084func Test_FiberHandler_ClosesBodyStream(t *testing.T) {
1085 t.Parallel()

Callers

nothing calls this directly

Calls 7

FlushMethod · 0.95
StatusCodeMethod · 0.95
FiberHandlerFuncFunction · 0.85
StatusMethod · 0.65
SendStreamWriterMethod · 0.65
WriteStringMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected