MCPcopy
hub / github.com/gin-gonic/gin / CreateTestContext

Function CreateTestContext

test_helpers.go:17–23  ·  test_helpers.go::CreateTestContext

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)

Source from the content-addressed store, hash-verified

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.
17func 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,

Calls 3

NewFunction · 0.85
allocateContextMethod · 0.80
resetMethod · 0.45