docs(test): improved GoDoc in test_helpers.go (#4270)

This commit is contained in:
諏訪原慶斗 2025-08-02 13:23:20 +09:00 committed by GitHub
parent 32065bbd42
commit 42f93283cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,10 @@ package gin
import "net/http" import "net/http"
// CreateTestContext returns a fresh engine and context for testing purposes // 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 writer.
func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) { func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
r = New() r = New()
c = r.allocateContext(0) c = r.allocateContext(0)
@ -15,7 +18,11 @@ func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
return return
} }
// CreateTestContextOnly returns a fresh context base on the engine for testing purposes // CreateTestContextOnly returns a fresh Context associated with the provided Engine `r`.
// This is useful for tests that operate on an existing, possibly pre-configured,
// Gin engine instance and need a new context for it.
// The ResponseWriter `w` is used to initialize the context's writer.
// The context is allocated with the `maxParams` setting from the provided engine.
func CreateTestContextOnly(w http.ResponseWriter, r *Engine) (c *Context) { func CreateTestContextOnly(w http.ResponseWriter, r *Engine) (c *Context) {
c = r.allocateContext(r.maxParams) c = r.allocateContext(r.maxParams)
c.reset() c.reset()