Test_ConvertRequest() — fiber Function Reference
Architecture documentation for the Test_ConvertRequest() function in adaptor_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD 9aeaa626_21c2_cfe5_36e4_0ced0a7247e9["Test_ConvertRequest()"] 8ec96b38_44b4_af66_6f6f_dd60f87b680c["adaptor_test.go"] 9aeaa626_21c2_cfe5_36e4_0ced0a7247e9 -->|defined in| 8ec96b38_44b4_af66_6f6f_dd60f87b680c style 9aeaa626_21c2_cfe5_36e4_0ced0a7247e9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/adaptor/adaptor_test.go lines 766–813
func Test_ConvertRequest(t *testing.T) {
t.Parallel()
t.Run("successful conversion", func(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Get("/test", func(c fiber.Ctx) error {
httpReq, err := ConvertRequest(c, false)
if err != nil {
return err
}
return c.SendString("Request URL: " + httpReq.URL.String())
})
resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/test?hello=world&another=test", http.NoBody))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, http.StatusOK, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, "Request URL: /test?hello=world&another=test", string(body))
})
t.Run("conversion error handling", func(t *testing.T) {
t.Parallel()
// Test error case by creating a context with an invalid URL that will cause fasthttpadaptor.ConvertRequest to fail
app := fiber.New()
ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
defer app.ReleaseCtx(ctx)
// Create a malformed request URI that should cause conversion to fail
ctx.Request().SetRequestURI("http://[::1:bad:url") // Invalid URL format
ctx.Request().Header.SetMethod(fiber.MethodGet)
_, err := ConvertRequest(ctx, true) // Use forServer=true which does more validation
if err == nil {
// If the above doesn't fail, try a different approach
ctx.Request().SetRequestURI("\x00\x01\x02") // Invalid characters in URI
_, err = ConvertRequest(ctx, true)
}
// Note: This test may pass if fasthttpadaptor is very permissive
// The important thing is that our function doesn't panic
if err != nil {
require.Error(t, err, "Expected error from fasthttpadaptor.ConvertRequest")
}
})
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_ConvertRequest() do?
Test_ConvertRequest() is a function in the fiber codebase, defined in middleware/adaptor/adaptor_test.go.
Where is Test_ConvertRequest() defined?
Test_ConvertRequest() is defined in middleware/adaptor/adaptor_test.go at line 766.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free