Test_HTTPHandler() — fiber Function Reference
Architecture documentation for the Test_HTTPHandler() function in adaptor_test.go from the fiber codebase.
Entity Profile
Dependency Diagram
graph TD e1608b1a_e6bf_240f_2b28_2729e1cf4698["Test_HTTPHandler()"] 8ec96b38_44b4_af66_6f6f_dd60f87b680c["adaptor_test.go"] e1608b1a_e6bf_240f_2b28_2729e1cf4698 -->|defined in| 8ec96b38_44b4_af66_6f6f_dd60f87b680c 1fb74a15_ad44_9be8_6f0d_226181223e63["setFiberContextValueMiddleware()"] e1608b1a_e6bf_240f_2b28_2729e1cf4698 -->|calls| 1fb74a15_ad44_9be8_6f0d_226181223e63 style e1608b1a_e6bf_240f_2b28_2729e1cf4698 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
middleware/adaptor/adaptor_test.go lines 34–116
func Test_HTTPHandler(t *testing.T) {
t.Parallel()
expectedMethod := fiber.MethodPost
expectedProto := "HTTP/1.1"
expectedProtoMajor := 1
expectedProtoMinor := 1
expectedContentLength := len(expectedBody)
expectedHeader := map[string]string{
"Foo-Bar": "baz",
"Abc": "defg",
"XXX-Remote-Addr": "123.43.4543.345",
}
expectedURL, err := url.ParseRequestURI(expectedRequestURI)
require.NoError(t, err)
type contextKeyType string
expectedContextKey := contextKeyType("contextKey")
expectedContextValue := "contextValue"
callsCount := 0
nethttpH := func(w http.ResponseWriter, r *http.Request) {
callsCount++
assert.Equal(t, expectedMethod, r.Method, "Method")
assert.Equal(t, expectedProto, r.Proto, "Proto")
assert.Equal(t, expectedProtoMajor, r.ProtoMajor, "ProtoMajor")
assert.Equal(t, expectedProtoMinor, r.ProtoMinor, "ProtoMinor")
assert.Equal(t, expectedRequestURI, r.RequestURI, "RequestURI")
assert.Equal(t, expectedContentLength, int(r.ContentLength), "ContentLength")
assert.Empty(t, r.TransferEncoding, "TransferEncoding")
assert.Equal(t, expectedHost, r.Host, "Host")
assert.Equal(t, expectedRemoteAddr, r.RemoteAddr, "RemoteAddr")
body, readErr := io.ReadAll(r.Body)
assert.NoError(t, readErr)
assert.Equal(t, expectedBody, string(body), "Body")
assert.Equal(t, expectedURL, r.URL, "URL")
assert.Equal(t, expectedContextValue, r.Context().Value(expectedContextKey), "Context")
for k, expectedV := range expectedHeader {
v := r.Header.Get(k)
assert.Equal(t, expectedV, v, "Header")
}
w.Header().Set("Header1", "value1")
w.Header().Set("Header2", "value2")
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "request body is %q", body)
}
fiberH := HTTPHandlerFunc(http.HandlerFunc(nethttpH))
fiberH = setFiberContextValueMiddleware(fiberH, expectedContextKey, expectedContextValue)
var fctx fasthttp.RequestCtx
var req fasthttp.Request
req.Header.SetMethod(expectedMethod)
req.SetRequestURI(expectedRequestURI)
req.Header.SetHost(expectedHost)
req.BodyWriter().Write([]byte(expectedBody)) //nolint:errcheck // not needed
for k, v := range expectedHeader {
req.Header.Set(k, v)
}
remoteAddr, err := net.ResolveTCPAddr("tcp", expectedRemoteAddr)
require.NoError(t, err)
fctx.Init(&req, remoteAddr, &disableLogger{})
app := fiber.New()
ctx := app.AcquireCtx(&fctx)
defer app.ReleaseCtx(ctx)
err = fiberH(ctx)
require.NoError(t, err)
require.Equal(t, 1, callsCount, "callsCount")
resp := &fctx.Response
require.Equal(t, http.StatusBadRequest, resp.StatusCode(), "StatusCode")
require.Equal(t, "value1", string(resp.Header.Peek("Header1")), "Header1")
require.Equal(t, "value2", string(resp.Header.Peek("Header2")), "Header2")
expectedResponseBody := fmt.Sprintf("request body is %q", expectedBody)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does Test_HTTPHandler() do?
Test_HTTPHandler() is a function in the fiber codebase, defined in middleware/adaptor/adaptor_test.go.
Where is Test_HTTPHandler() defined?
Test_HTTPHandler() is defined in middleware/adaptor/adaptor_test.go at line 34.
What does Test_HTTPHandler() call?
Test_HTTPHandler() calls 1 function(s): setFiberContextValueMiddleware.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free