test_helpers.go 673 B

123456789101112131415161718192021222324
  1. // Copyright 2017 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package gin
  5. import "net/http"
  6. // CreateTestContext returns a fresh engine and context for testing purposes
  7. func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
  8. r = New()
  9. c = r.allocateContext(0)
  10. c.reset()
  11. c.writermem.reset(w)
  12. return
  13. }
  14. // CreateTestContextOnly returns a fresh context base on the engine for testing purposes
  15. func CreateTestContextOnly(w http.ResponseWriter, r *Engine) (c *Context) {
  16. c = r.allocateContext(r.maxParams)
  17. c.reset()
  18. c.writermem.reset(w)
  19. return
  20. }