github.com/influx6/npkg@v0.8.8/nhttp/httptests/httptesting.go (about) 1 package httptests 2 3 import ( 4 "io" 5 "net/http" 6 "net/http/httptest" 7 8 "github.com/influx6/npkg/nhttp" 9 ) 10 11 // GET returns a new Context using GET method. 12 func Get(path string, body io.Reader, res *httptest.ResponseRecorder) *nhttp.Ctx { 13 return NewRequest("GET", path, body, res) 14 } 15 16 // Delete returns a new Context using DELETE method. 17 func Delete(path string, body io.Reader, res *httptest.ResponseRecorder) *nhttp.Ctx { 18 return NewRequest("DELETE", path, body, res) 19 } 20 21 // Put returns a new Context using PUT method. 22 func Put(path string, body io.Reader, res *httptest.ResponseRecorder) *nhttp.Ctx { 23 return NewRequest("PUT", path, body, res) 24 } 25 26 // Post returns a new Context using PUT method. 27 func Post(path string, body io.Reader, res *httptest.ResponseRecorder) *nhttp.Ctx { 28 return NewRequest("POST", path, body, res) 29 } 30 31 // Patch returns a new Context using PUT method. 32 func Patch(path string, body io.Reader, res *httptest.ResponseRecorder) *nhttp.Ctx { 33 return NewRequest("PATCH", path, body, res) 34 } 35 36 // NewRequest returns a new instance of a nhttp.Context with provided parameters. 37 func NewRequest(method string, path string, body io.Reader, res http.ResponseWriter) *nhttp.Ctx { 38 req := httptest.NewRequest(method, path, body) 39 return nhttp.NewContext( 40 nhttp.SetRequest(req), 41 nhttp.SetResponseWriter(res), 42 ) 43 }