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
+69 -23
View File
@@ -26,7 +26,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// OPDS endpoints require device authentication via devices.auth_token
assert.Equal(t, http.StatusUnauthorized, resp.StatusCode)
@@ -37,7 +39,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should return 400 for invalid UUID
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
@@ -53,7 +57,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should return 200 with catalog (even if empty)
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -69,7 +75,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should return 200 with catalog (even if empty)
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -80,7 +88,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
@@ -95,7 +105,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should return 200 (even if empty results)
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -106,7 +118,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
@@ -120,7 +134,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should return navigation or 404
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound)
@@ -131,7 +147,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
@@ -142,7 +160,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
@@ -156,7 +176,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// May return 404 if device/book not linked, or 500 for file not found
// Should not return 400 (invalid IDs)
@@ -168,7 +190,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
@@ -178,7 +202,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
@@ -192,7 +218,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// May return 404 if no cover, but not 400
assert.NotEqual(t, http.StatusBadRequest, resp.StatusCode)
@@ -204,7 +232,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
@@ -218,7 +248,9 @@ func TestOPDSEndpoints(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should return formats list or 404
assert.True(t, resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNotFound)
@@ -245,7 +277,9 @@ func TestOPDSConversion(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should attempt conversion (may fail if file doesn't exist)
// Important: Should not return 400 for invalid IDs
@@ -262,7 +296,9 @@ func TestOPDSConversion(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should attempt to download original format
assert.NotEqual(t, http.StatusBadRequest, resp.StatusCode)
@@ -278,7 +314,9 @@ func TestOPDSConversion(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should handle gracefully (either 400 for unsupported format or 404/500)
assert.True(t, resp.StatusCode >= 400 && resp.StatusCode < 600)
@@ -300,7 +338,9 @@ func TestOPDSEdgeCases(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should return empty catalog, not error
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -316,7 +356,9 @@ func TestOPDSEdgeCases(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should handle special characters
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -331,7 +373,9 @@ func TestOPDSEdgeCases(t *testing.T) {
resp, err := client.Do(httpReq)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
// Should handle empty query
assert.True(t, resp.StatusCode >= 200 && resp.StatusCode < 500)
@@ -371,7 +415,9 @@ func TestOPDSSearchAcrossLibraries(t *testing.T) {
resp, err := client.Do(req)
require.NoError(t, err)
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(resp.Body)
t.Logf("OPDS Search Status: %d", resp.StatusCode)