2016-01-28 23:56:09 -08:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/engine"
|
|
|
|
"github.com/labstack/echo/engine/standard"
|
2016-02-04 19:29:49 -08:00
|
|
|
"github.com/labstack/gommon/log"
|
2016-01-28 23:56:09 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
ResponseRecorder struct {
|
|
|
|
engine.Response
|
|
|
|
Body *bytes.Buffer
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewRequest(method, url string, body io.Reader) engine.Request {
|
2016-02-08 22:17:20 -08:00
|
|
|
// switch t {
|
|
|
|
// case engine.Standard:
|
2016-01-28 23:56:09 -08:00
|
|
|
r, _ := http.NewRequest(method, url, body)
|
|
|
|
return standard.NewRequest(r)
|
2016-02-08 22:17:20 -08:00
|
|
|
// default:
|
|
|
|
// panic("invalid engine")
|
|
|
|
// }
|
2016-01-28 23:56:09 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewResponseRecorder() *ResponseRecorder {
|
|
|
|
r := httptest.NewRecorder()
|
|
|
|
return &ResponseRecorder{
|
2016-02-04 19:29:49 -08:00
|
|
|
Response: standard.NewResponse(r, log.New("test")),
|
2016-01-28 23:56:09 -08:00
|
|
|
Body: r.Body,
|
|
|
|
}
|
|
|
|
}
|