CreateTestContext returns a fresh Engine and a Context associated with it. This is useful for tests that need to set up a new Gin engine instance along with a context, for example, to test middleware that doesn't depend on specific routes. The ResponseWriter `w` is used to initialize the context's w
(w http.ResponseWriter)
| 15 | // along with a context, for example, to test middleware that doesn't depend on |
| 16 | // specific routes. The ResponseWriter `w` is used to initialize the context's writer. |
| 17 | func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) { |
| 18 | r = New() |
| 19 | c = r.allocateContext(0) |
| 20 | c.reset() |
| 21 | c.writermem.reset(w) |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | // CreateTestContextOnly returns a fresh Context associated with the provided Engine `r`. |
| 26 | // This is useful for tests that operate on an existing, possibly pre-configured, |