@@ -59,24 +59,13 @@ func (m *mockBody) Close() error {
59
59
return nil
60
60
}
61
61
62
- // limitedBadResponseWriter is a custom io.Writer implementation that simulates
63
- // write errors for a specified number of attempts. After a certain number of failures,
64
- // it allows the write operation to succeed.
65
- type limitedBadResponseWriter struct {
66
- failCount int
67
- maxFailures int
62
+ // brokenWriter implements the io.Writer interface.
63
+ type brokenWriter struct {
64
+ http.ResponseWriter
68
65
}
69
66
70
- // Write simulates writing data to the writer. It forces an error response for
71
- // a limited number of attempts, specified by maxFailures. Once failCount reaches
72
- // maxFailures, it allows the write to succeed.
73
- func (b * limitedBadResponseWriter ) Write (p []byte ) (n int , err error ) {
74
- if b .failCount < b .maxFailures {
75
- b .failCount ++
76
- return 0 , errors .New ("forced write error" )
77
- }
78
- // After reaching maxFailures, allow the write to succeed to stop the infinite loop.
79
- return len (p ), nil
67
+ func (bw * brokenWriter ) Write (_ []byte ) (int , error ) {
68
+ return 0 , fmt .Errorf ("mock: write: broken pipe" )
80
69
}
81
70
82
71
func TestServeHTTP (t * testing.T ) {
@@ -294,20 +283,14 @@ func TestWriteResourceInterpreterResponse(t *testing.T) {
294
283
},
295
284
},
296
285
{
297
- name : "WriteResourceInterpreterResponse_FailedToWrite_WriterReachedMaxFailures " ,
286
+ name : "should never run into circular calling if the writer has broken " ,
298
287
mockHandler : & HTTPMockHandler {},
299
288
res : configv1alpha1.ResourceInterpreterContext {
300
289
Response : & configv1alpha1.ResourceInterpreterResponse {},
301
290
},
302
- rec : & limitedBadResponseWriter {maxFailures : 3 },
303
- verify : func (writer io.Writer , _ * configv1alpha1.ResourceInterpreterResponse ) error {
304
- data , ok := writer .(* limitedBadResponseWriter )
305
- if ! ok {
306
- return fmt .Errorf ("expected writer of type limitedBadResponseWriter but got %T" , writer )
307
- }
308
- if data .failCount != data .maxFailures {
309
- return fmt .Errorf ("expected %d write failures, got %d" , data .maxFailures , data .failCount )
310
- }
291
+ rec : & brokenWriter {},
292
+ verify : func (_ io.Writer , _ * configv1alpha1.ResourceInterpreterResponse ) error {
293
+ // reaching here means not running into circular calling
311
294
return nil
312
295
},
313
296
},
0 commit comments