New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit testing middleware with CreateTestContext #2816
Comments
@ri-ch But the problem lies in the function ServeHTTP() You can see that the key in the current context has no value. You can look at the source code of engine.pool.Get().(*Context)
The context at this time is no longer the first context, it is random. This is my code
|
Just encountered the exact same issue. did you ever figure out a way to solve this?
|
This seems to be duplicate of #1292 which has a workaround that works for me. |
Description
Im trying to unit test some gin middeware. This middleware accepts a
gin.Context
and performs an action based on fields in the context.I can see I can create a test context using
gin.CreateTestContext()
which returns a new context and an engine.I would like to modify the context to set the preconditions for my test, but it is not clear how I would use the modified context.
How to reproduce
### Middleware
The middleware test
Expectations
I should be able to inject the modified context in order to test my middleware
Actual result
There doesn't appear to be a way to inject the context
Environment
The text was updated successfully, but these errors were encountered: