Open 1Mark opened 1 year ago
@1Mark It's been few months. Maybe this test from the repository will help you rewrite you're test if you still need any help.
Perhaps this?
var match mux.RouteMatch
var handler http.Handler
req := &http.Request{}
req.URL = &url.URL{Path: "/post"}
req.Method = "POST"
if builder.router.Match(req, &match) {
// Get the matched handler along with middleware
matchedHandler := match.MatchedHandler
// Define a temporary http.HandlerFunc to capture the inner handler
tempHandlerFunc := func(w http.ResponseWriter, r *http.Request) {
handler = matchedHandler
}
// Call the middleware with the temporary handler
for _, mw := range match.Handler.Middlewares() {
tempHandlerFunc = mw(tempHandlerFunc)
}
// Now 'handler' should contain the inner handler without middleware
}
g.Expect(handler).ToNot(BeNil())
fmt.Println(handler)
Unrelated, but I'm looking to contribute to this project in any capacity, but all I'm seeing in Issues are questions and discussions.
I'm trying to write a test to confirm that both the POST and PATCH methods of the same URL go to the same handler. So I tried the following
handler
func is actually the handler func but wrapped in the MDW. Therefore, I couldn't assert that thehandler
was equal to my desired handler funcAny tips ?