File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -578,3 +578,16 @@ func TestRenderReaderNoContentLength(t *testing.T) {
578578 assert .Equal (t , headers ["Content-Disposition" ], w .Header ().Get ("Content-Disposition" ))
579579 assert .Equal (t , headers ["x-request-id" ], w .Header ().Get ("x-request-id" ))
580580}
581+
582+ func TestRenderWriteError (t * testing.T ) {
583+ data := []interface {}{"value1" , "value2" }
584+ prefix := "my-prefix:"
585+ r := SecureJSON {Data : data , Prefix : prefix }
586+ ew := & errorWriter {
587+ bufString : prefix ,
588+ ResponseRecorder : httptest .NewRecorder (),
589+ }
590+ err := r .Render (ew )
591+ assert .NotNil (t , err )
592+ assert .Equal (t , `write "my-prefix:" error` , err .Error ())
593+ }
Original file line number Diff line number Diff line change @@ -156,3 +156,33 @@ func TestResponseWriterStatusCode(t *testing.T) {
156156 // status must be 200 although we tried to change it
157157 assert .Equal (t , http .StatusOK , w .Status ())
158158}
159+
160+ // mockPusherResponseWriter is an http.ResponseWriter that implements http.Pusher.
161+ type mockPusherResponseWriter struct {
162+ http.ResponseWriter
163+ }
164+
165+ func (m * mockPusherResponseWriter ) Push (target string , opts * http.PushOptions ) error {
166+ return nil
167+ }
168+
169+ // nonPusherResponseWriter is an http.ResponseWriter that does not implement http.Pusher.
170+ type nonPusherResponseWriter struct {
171+ http.ResponseWriter
172+ }
173+
174+ func TestPusherWithPusher (t * testing.T ) {
175+ rw := & mockPusherResponseWriter {}
176+ w := & responseWriter {ResponseWriter : rw }
177+
178+ pusher := w .Pusher ()
179+ assert .NotNil (t , pusher , "Expected pusher to be non-nil" )
180+ }
181+
182+ func TestPusherWithoutPusher (t * testing.T ) {
183+ rw := & nonPusherResponseWriter {}
184+ w := & responseWriter {ResponseWriter : rw }
185+
186+ pusher := w .Pusher ()
187+ assert .Nil (t , pusher , "Expected pusher to be nil" )
188+ }
You can’t perform that action at this time.
0 commit comments