fix(tests): handle all Close() and Decode() errors across integration tests
Replace all unhandled resp.Body.Close() calls throughout the test suite:
- Deferred calls: replace 'defer VAR.Body.Close()' with a closure that explicitly
discards the error via 'defer func(Body io.ReadCloser) { _ = Body.Close() }(VAR.Body)'
- Immediate calls: replace 'VAR.Body.Close()' with '_ = VAR.Body.Close()'
Replace all unhandled json.NewDecoder(VAR.Body).Decode(&x) calls with error capture
and require.NoError assertion. Files using httptest.ResponseRecorder (collections_preview,
processing_issues) use 'err :=' declaration; suite-style tests (scanner_integration,
dashboard_integration) use s.T() instead of t.
This commit is contained in:
@@ -46,8 +46,9 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() {
|
||||
require.Equal(s.T(), http.StatusCreated, createLibResp.StatusCode)
|
||||
|
||||
var createLibResponse map[string]interface{}
|
||||
json.NewDecoder(createLibResp.Body).Decode(&createLibResponse)
|
||||
createLibResp.Body.Close()
|
||||
err = json.NewDecoder(createLibResp.Body).Decode(&createLibResponse)
|
||||
require.NoError(s.T(), err)
|
||||
_ = createLibResp.Body.Close()
|
||||
|
||||
libraryID, ok := createLibResponse["id"].(string)
|
||||
require.True(s.T(), ok, "library_id should be string")
|
||||
@@ -64,7 +65,7 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() {
|
||||
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(s.T(), err)
|
||||
resp.Body.Close()
|
||||
_ = resp.Body.Close()
|
||||
require.Equal(s.T(), http.StatusCreated, resp.StatusCode, "Folder creation should succeed")
|
||||
|
||||
scanURL := fmt.Sprintf("%s/api/libraries/%s/scan", s.setup.Server.URL, libraryID)
|
||||
@@ -78,7 +79,7 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() {
|
||||
var scanResponse map[string]interface{}
|
||||
err = json.NewDecoder(scanResp.Body).Decode(&scanResponse)
|
||||
require.NoError(s.T(), err)
|
||||
scanResp.Body.Close()
|
||||
_ = scanResp.Body.Close()
|
||||
|
||||
jobID, ok := scanResponse["job_id"].(string)
|
||||
require.True(s.T(), ok, "job_id should be string")
|
||||
@@ -104,7 +105,7 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() {
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
if statusResp.StatusCode == http.StatusNotFound {
|
||||
statusResp.Body.Close()
|
||||
_ = statusResp.Body.Close()
|
||||
if gotProgressUpdate {
|
||||
break
|
||||
}
|
||||
@@ -113,7 +114,7 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_TracksStatistics() {
|
||||
|
||||
var status map[string]interface{}
|
||||
err = json.NewDecoder(statusResp.Body).Decode(&status)
|
||||
statusResp.Body.Close()
|
||||
_ = statusResp.Body.Close()
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
if _, hasError := status["error"]; hasError {
|
||||
@@ -180,8 +181,9 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_BatchingWorks() {
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
var createLibResponse map[string]interface{}
|
||||
json.NewDecoder(createLibResp.Body).Decode(&createLibResponse)
|
||||
createLibResp.Body.Close()
|
||||
err = json.NewDecoder(createLibResp.Body).Decode(&createLibResponse)
|
||||
require.NoError(s.T(), err)
|
||||
_ = createLibResp.Body.Close()
|
||||
|
||||
libraryID, ok := createLibResponse["id"].(string)
|
||||
require.True(s.T(), ok, "library_id should be string")
|
||||
@@ -198,7 +200,7 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_BatchingWorks() {
|
||||
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(s.T(), err)
|
||||
resp.Body.Close()
|
||||
_ = resp.Body.Close()
|
||||
|
||||
scanURL := fmt.Sprintf("%s/api/libraries/%s/scan", s.setup.Server.URL, libraryID)
|
||||
scanReq, _ := http.NewRequest("POST", scanURL, nil)
|
||||
@@ -208,8 +210,9 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_BatchingWorks() {
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
var scanResponse map[string]interface{}
|
||||
json.NewDecoder(scanResp.Body).Decode(&scanResponse)
|
||||
scanResp.Body.Close()
|
||||
err = json.NewDecoder(scanResp.Body).Decode(&scanResponse)
|
||||
require.NoError(s.T(), err)
|
||||
_ = scanResp.Body.Close()
|
||||
|
||||
jobID, ok := scanResponse["job_id"].(string)
|
||||
require.True(s.T(), ok, "job_id should be string")
|
||||
@@ -231,14 +234,14 @@ func (s *ScannerIntegrationTestSuite) TestScanProgress_BatchingWorks() {
|
||||
require.NoError(s.T(), err)
|
||||
|
||||
if statusResp.StatusCode == http.StatusNotFound {
|
||||
statusResp.Body.Close()
|
||||
_ = statusResp.Body.Close()
|
||||
break
|
||||
}
|
||||
|
||||
var status map[string]interface{}
|
||||
err = json.NewDecoder(statusResp.Body).Decode(&status)
|
||||
require.NoError(s.T(), err)
|
||||
statusResp.Body.Close()
|
||||
_ = statusResp.Body.Close()
|
||||
|
||||
if _, hasError := status["error"]; hasError {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user