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

Function Test_FiberHandler_IOError

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

Source from the content-addressed store, hash-verified

1002}
1003
1004func Test_FiberHandler_IOError(t *testing.T) {
1005 t.Parallel()
1006
1007 // Test io.Copy error by using a failing reader
1008 fiberH := func(c fiber.Ctx) error {
1009 return c.SendString("should not reach here")
1010 }
1011 handlerFunc := FiberHandlerFunc(fiberH)
1012
1013 // Create a reader that fails
1014 failingReader := &failingReader{}
1015
1016 r := &http.Request{
1017 Method: http.MethodPost,
1018 RequestURI: "/test",
1019 Body: failingReader,
1020 ContentLength: 100, // Set content length so it tries to read
1021 Header: make(http.Header),
1022 }
1023
1024 w := &netHTTPResponseWriter{}
1025 handlerFunc.ServeHTTP(w, r)
1026
1027 // Should return 500 due to io.Copy error
1028 require.Equal(t, http.StatusInternalServerError, w.StatusCode())
1029}
1030
1031func Test_FiberHandler_WithErrorInHandler(t *testing.T) {
1032 t.Parallel()

Callers

nothing calls this directly

Calls 4

StatusCodeMethod · 0.95
FiberHandlerFuncFunction · 0.85
SendStringMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected