github.com/seeker-insurance/kit@v0.0.13/web/webtest/webtest.go (about) 1 package webtest 2 3 import ( 4 "net/http/httptest" 5 "strings" 6 7 "github.com/labstack/echo" 8 ) 9 10 func Post(url, json string) (ctx echo.Context, rec *httptest.ResponseRecorder) { 11 req := httptest.NewRequest(echo.POST, url, strings.NewReader(json)) 12 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) 13 rec = httptest.NewRecorder() 14 ctx = echo.New().NewContext(req, rec) 15 return ctx, rec 16 } 17 18 func Get(url, json string) (ctx echo.Context, rec *httptest.ResponseRecorder) { 19 req := httptest.NewRequest(echo.GET, url, strings.NewReader(json)) 20 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) 21 rec = httptest.NewRecorder() 22 ctx = echo.New().NewContext(req, rec) 23 return ctx, rec 24 } 25 26 func Patch(url, json string) (ctx echo.Context, rec *httptest.ResponseRecorder) { 27 req := httptest.NewRequest(echo.PATCH, url, strings.NewReader(json)) 28 req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON) 29 rec = httptest.NewRecorder() 30 ctx = echo.New().NewContext(req, rec) 31 return ctx, rec 32 }