mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 16:30:01 +08:00
chore: add unit test for WithCodeResponseWriter (#5028)
Signed-off-by: kevin <wanjunfeng@gmail.com>
This commit is contained in:
@@ -49,6 +49,12 @@ func (w *WithCodeResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return nil, nil, errors.New("server doesn't support hijacking")
|
||||
}
|
||||
|
||||
// Unwrap returns the underlying http.ResponseWriter.
|
||||
// This is used by http.ResponseController to unwrap the response writer.
|
||||
func (w *WithCodeResponseWriter) Unwrap() http.ResponseWriter {
|
||||
return w.Writer
|
||||
}
|
||||
|
||||
// Write writes bytes into w.
|
||||
func (w *WithCodeResponseWriter) Write(bytes []byte) (int, error) {
|
||||
return w.Writer.Write(bytes)
|
||||
@@ -59,8 +65,3 @@ func (w *WithCodeResponseWriter) WriteHeader(code int) {
|
||||
w.Writer.WriteHeader(code)
|
||||
w.Code = code
|
||||
}
|
||||
|
||||
// Unwrap returns the underlying ResponseWriter.
|
||||
func (w *WithCodeResponseWriter) Unwrap() http.ResponseWriter {
|
||||
return w.Writer
|
||||
}
|
||||
|
||||
@@ -46,3 +46,15 @@ func TestWithCodeResponseWriter_Hijack(t *testing.T) {
|
||||
writer.Hijack()
|
||||
})
|
||||
}
|
||||
|
||||
func TestWithCodeResponseWriter_Unwrap(t *testing.T) {
|
||||
resp := httptest.NewRecorder()
|
||||
writer := NewWithCodeResponseWriter(resp)
|
||||
unwrapped := writer.Unwrap()
|
||||
assert.Equal(t, resp, unwrapped)
|
||||
|
||||
// Test with a nested WithCodeResponseWriter
|
||||
nestedWriter := NewWithCodeResponseWriter(writer)
|
||||
unwrappedNested := nestedWriter.Unwrap()
|
||||
assert.Equal(t, resp, unwrappedNested)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user