-
Notifications
You must be signed in to change notification settings - Fork 3
/
webtest.go
32 lines (27 loc) · 1004 Bytes
/
webtest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package webtest
import (
"net/http/httptest"
"strings"
"github.com/labstack/echo"
)
func Post(url, json string) (ctx echo.Context, rec *httptest.ResponseRecorder) {
req := httptest.NewRequest(echo.POST, url, strings.NewReader(json))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec = httptest.NewRecorder()
ctx = echo.New().NewContext(req, rec)
return ctx, rec
}
func Get(url, json string) (ctx echo.Context, rec *httptest.ResponseRecorder) {
req := httptest.NewRequest(echo.GET, url, strings.NewReader(json))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec = httptest.NewRecorder()
ctx = echo.New().NewContext(req, rec)
return ctx, rec
}
func Patch(url, json string) (ctx echo.Context, rec *httptest.ResponseRecorder) {
req := httptest.NewRequest(echo.PATCH, url, strings.NewReader(json))
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
rec = httptest.NewRecorder()
ctx = echo.New().NewContext(req, rec)
return ctx, rec
}