@@ -59,6 +59,10 @@ func (suite *RequestsTestSuite) SetupSuite() {
5959 Get ("/fail/" ).
6060 Reply (500 ).
6161 BodyString ("server broken" )
62+ suite .fakeService .NewHandler ().
63+ Get ("/proxy-block/" ).
64+ Reply (403 ).
65+ BodyString (`<!DOCTYPE html><html><body><h1>403 Forbidden</h1><p>Blocked by proxy</p></body></html>` )
6266}
6367
6468// shutdown the fake service after the suite execution
@@ -262,6 +266,7 @@ func (suite *RequestsTestSuite) TestDo() {
262266 for _ , t := range []struct {
263267 name string
264268 params * RequestParams
269+ debug bool
265270 wantError bool
266271 expectedLog string
267272 expectedErrorMsg string
@@ -377,15 +382,29 @@ func (suite *RequestsTestSuite) TestDo() {
377382 wantError : true ,
378383 expectedErrorMsg : "unexpected end of JSON input" ,
379384 },
385+ {
386+ name : "non-JSON error response body is logged with debug enabled" ,
387+ params : & RequestParams {
388+ Method : http .MethodGet ,
389+ URL : suite .fakeService .ResolveURL ("/proxy-block/" ),
390+ },
391+ debug : true ,
392+ wantError : true ,
393+ expectedErrorMsg : "invalid character '<' looking for beginning of value" ,
394+ expectedLog : `<!DOCTYPE html><html><body><h1>403 Forbidden</h1><p>Blocked by proxy</p></body></html>` ,
395+ },
380396 } {
381397 suite .Run (t .name , func () {
382398 buf := new (bytes.Buffer )
383- client , err := NewKosliClient ("" , 1 , false , logger .NewLogger (buf , buf , false ))
399+ client , err := NewKosliClient ("" , 1 , t . debug , logger .NewLogger (buf , buf , t . debug ))
384400 require .NoError (suite .T (), err )
385401 resp , err := client .Do (t .params )
386402 if t .wantError {
387403 require .Error (suite .T (), err )
388404 require .Equal (suite .T (), t .expectedErrorMsg , err .Error ())
405+ if t .expectedLog != "" {
406+ require .Contains (suite .T (), buf .String (), t .expectedLog )
407+ }
389408 } else {
390409 require .NoError (suite .T (), err )
391410 output := buf .String ()
0 commit comments