mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-19 21:18:07 +02:00
This commit is contained in:
parent
1fdaabbd48
commit
26d7d5fa00
@ -57,6 +57,7 @@ func (w *responseWriter) Write(data []byte) (int, error) {
|
|||||||
w.w.WriteHeader(w.code)
|
w.w.WriteHeader(w.code)
|
||||||
return w.w.Write(data)
|
return w.w.Write(data)
|
||||||
}
|
}
|
||||||
|
func (w *responseWriter) Unwrap() http.ResponseWriter { return w.w }
|
||||||
|
|
||||||
type wrapper struct {
|
type wrapper struct {
|
||||||
router *Router
|
router *Router
|
||||||
|
@ -100,6 +100,34 @@ func TestContextResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResponseUnwrap(t *testing.T) {
|
||||||
|
res := httptest.NewRecorder()
|
||||||
|
f := func(rw http.ResponseWriter, r *http.Request, a interface{}) error {
|
||||||
|
u, ok := rw.(interface {
|
||||||
|
Unwrap() http.ResponseWriter
|
||||||
|
})
|
||||||
|
if !ok {
|
||||||
|
return errors.New("can not unwrap")
|
||||||
|
}
|
||||||
|
w := u.Unwrap()
|
||||||
|
if !reflect.DeepEqual(w, res) {
|
||||||
|
return errors.New("underlying response writer not equal")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
w := wrapper{
|
||||||
|
router: &Router{srv: &Server{enc: f}},
|
||||||
|
req: nil,
|
||||||
|
res: res,
|
||||||
|
w: responseWriter{200, res},
|
||||||
|
}
|
||||||
|
err := w.Result(200, "ok")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected %v, got %v", nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContextBindQuery(t *testing.T) {
|
func TestContextBindQuery(t *testing.T) {
|
||||||
w := wrapper{
|
w := wrapper{
|
||||||
router: testRouter,
|
router: testRouter,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user