@@ -10,6 +10,7 @@ import (
1010 "time"
1111
1212 "github.com/stretchr/testify/assert"
13+ "github.com/zeromicro/go-zero/core/logx/logtest"
1314 "github.com/zeromicro/go-zero/rest/internal"
1415 "github.com/zeromicro/go-zero/rest/internal/response"
1516)
@@ -86,6 +87,26 @@ func TestLogHandlerSlow(t *testing.T) {
8687 assert .Equal (t , http .StatusOK , resp .Code )
8788 }
8889}
90+
91+ func TestDetailedLogHandler_LargeBody (t * testing.T ) {
92+ lbuf := logtest .NewCollector (t )
93+
94+ var buf bytes.Buffer
95+ for i := 0 ; i < limitDetailedBodyBytes << 2 ; i ++ {
96+ buf .WriteByte ('a' )
97+ }
98+
99+ req := httptest .NewRequest (http .MethodPost , "http://localhost" , & buf )
100+ h := DetailedLogHandler (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
101+ io .Copy (io .Discard , r .Body )
102+ }))
103+ resp := httptest .NewRecorder ()
104+ h .ServeHTTP (resp , req )
105+
106+ // extra 200 for the length of POST request headers
107+ assert .True (t , len (lbuf .Content ()) < limitDetailedBodyBytes + 200 )
108+ }
109+
89110func TestDetailedLogHandler_Hijack (t * testing.T ) {
90111 resp := httptest .NewRecorder ()
91112 writer := & detailLoggedResponseWriter {
@@ -111,6 +132,7 @@ func TestDetailedLogHandler_Hijack(t *testing.T) {
111132 _ , _ , _ = writer .Hijack ()
112133 })
113134}
135+
114136func TestSetSlowThreshold (t * testing.T ) {
115137 assert .Equal (t , defaultSlowThreshold , slowThreshold .Load ())
116138 SetSlowThreshold (time .Second )
0 commit comments