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.
- app.Test(req *http.Request, msTimeout ...int) (*http.Response, error)
- // Create route with GET method for test:
- app.Get("/", func(c *Ctx) {
- fmt.Println(c.BaseURL()) // => http://google.com
- fmt.Println(c.Get("X-Custom-Header")) // => hi
- c.Send("hello, World!")
- })
- // http.Request
- req, _ := http.NewRequest("GET", "http://google.com", nil)
- req.Header.Set("X-Custom-Header", "hi")
- // http.Response
- resp, _ := app.Test(req)
- // Do something with results:
- if resp.StatusCode == 200 {
- body, _ := ioutil.ReadAll(resp.Body)
- fmt.Println(string(body)) // => Hello, World!
- }