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:
@@ -41,8 +41,9 @@ func TestWorker_DirectoryScanJob(t *testing.T) {
|
||||
require.Equal(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(t, err)
|
||||
_ = createLibResp.Body.Close()
|
||||
|
||||
libraryID, ok := createLibResponse["id"].(string)
|
||||
require.True(t, ok)
|
||||
@@ -62,7 +63,7 @@ func TestWorker_DirectoryScanJob(t *testing.T) {
|
||||
|
||||
resp, err := client.Do(req)
|
||||
require.NoError(t, err)
|
||||
resp.Body.Close()
|
||||
_ = resp.Body.Close()
|
||||
require.Equal(t, http.StatusCreated, resp.StatusCode)
|
||||
|
||||
// Create test files in the directory
|
||||
@@ -141,8 +142,9 @@ func TestWorker_SetFoldersJob(t *testing.T) {
|
||||
require.Equal(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(t, err)
|
||||
_ = createLibResp.Body.Close()
|
||||
|
||||
libraryID, ok := createLibResponse["id"].(string)
|
||||
require.True(t, ok)
|
||||
|
||||
Reference in New Issue
Block a user