Test

Testing your application is done with the Test method. Use this method for creating _test.go files or when you need to debug your routing logic. The default timeout is 200ms if you want to disable a timeout completely, pass -1 as a second argument.

  1. app.Test(req *http.Request, msTimeout ...int) (*http.Response, error)
  1. // Create route with GET method for test:
  2. app.Get("/", func(c *Ctx) {
  3. fmt.Println(c.BaseURL()) // => http://google.com
  4. fmt.Println(c.Get("X-Custom-Header")) // => hi
  5.  
  6. c.Send("hello, World!")
  7. })
  8.  
  9. // http.Request
  10. req, _ := http.NewRequest("GET", "http://google.com", nil)
  11. req.Header.Set("X-Custom-Header", "hi")
  12.  
  13. // http.Response
  14. resp, _ := app.Test(req)
  15.  
  16. // Do something with results:
  17. if resp.StatusCode == 200 {
  18. body, _ := ioutil.ReadAll(resp.Body)
  19. fmt.Println(string(body)) // => Hello, World!
  20. }