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

Function Test_App_Test_CloseFail

app_test.go:3053–3083  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3051}
3052
3053func Test_App_Test_CloseFail(t *testing.T) {
3054 // Note: Test cannot run in parallel due to
3055 // overriding the httpReadResponse global variable.
3056 // t.Parallel()
3057
3058 // Override httpReadResponse temporarily
3059 oldHTTPReadResponse := httpReadResponse
3060 defer func() {
3061 httpReadResponse = oldHTTPReadResponse
3062 }()
3063
3064 httpReadResponse = func(r *bufio.Reader, req *http.Request) (*http.Response, error) {
3065 resp, err := http.ReadResponse(r, req)
3066 _ = resp.Body.Close() //nolint:errcheck // It is fine to ignore the error here
3067 resp.Body = &doubleCloseBody{}
3068 return resp, err //nolint:wrapcheck // unnecessary to wrap it
3069 }
3070
3071 app := New()
3072 hints := []string{"<https://cdn.com>; rel=preload; as=script"}
3073 app.Get("/early", func(c Ctx) error {
3074 err := c.SendEarlyHints(hints)
3075 require.NoError(t, err)
3076 return c.Status(StatusOK).SendString("done")
3077 })
3078
3079 req := httptest.NewRequest(MethodGet, "/early", http.NoBody)
3080 _, err := app.Test(req)
3081
3082 require.ErrorIs(t, err, errDoubleClose)
3083}
3084
3085func Test_App_SetTLSHandler(t *testing.T) {
3086 t.Parallel()

Callers

nothing calls this directly

Calls 7

TestMethod · 0.80
NewFunction · 0.70
CloseMethod · 0.65
GetMethod · 0.65
SendEarlyHintsMethod · 0.65
SendStringMethod · 0.65
StatusMethod · 0.65

Tested by

no test coverage detected