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:
2026-04-21 20:33:05 -04:00
parent 8baecad379
commit a6700f73e0
28 changed files with 1065 additions and 414 deletions
+9 -3
View File
@@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"sync"
@@ -98,11 +99,14 @@ func createTestLibraryWithFolder(t *testing.T, ts *httptest.Server, token, name
client := &http.Client{}
resp, err := client.Do(libHTTP)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
require.Equal(t, http.StatusCreated, resp.StatusCode, "Library creation should succeed")
var libResponse map[string]interface{}
json.NewDecoder(resp.Body).Decode(&libResponse)
err = json.NewDecoder(resp.Body).Decode(&libResponse)
require.NoError(t, err)
libraryID := libResponse["id"].(string)
if withFolder {
@@ -117,7 +121,9 @@ func createTestLibraryWithFolder(t *testing.T, ts *httptest.Server, token, name
folderResp, err := client.Do(folderHTTP)
require.NoError(t, err)
defer folderResp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(folderResp.Body)
require.Equal(t, http.StatusCreated, folderResp.StatusCode, "Folder creation should succeed")
}