From 65c860bb99e44201d249d8f07125bb84545bdf10 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 22 Apr 2026 15:44:01 -0400 Subject: [PATCH] fix(tests): handle 404 response for nonexistent library in search filter test TestCollectionSearchLibraryFilter's 'invalid library_id' case was expecting a 200 with empty results, but the search handler correctly returns 404 when no results are found. The test also consumed the response body for debug logging then tried to JSON-decode the same body (causing EOF). Add expectedStatus field to the test struct and return early when a specific non-200 status is expected. --- cmd/server/tests/search_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/server/tests/search_test.go b/cmd/server/tests/search_test.go index ae9a1f0..32ae25c 100644 --- a/cmd/server/tests/search_test.go +++ b/cmd/server/tests/search_test.go @@ -388,6 +388,7 @@ func TestCollectionSearchLibraryFilter(t *testing.T) { query string libraryID string expectedCount int + expectedStatus int shouldContain string // Comma-separated list of book IDs to check }{ { @@ -412,10 +413,10 @@ func TestCollectionSearchLibraryFilter(t *testing.T) { shouldContain: book2ID, }, { - name: "invalid library_id", - query: "Harry", - libraryID: "00000000-0000-0000-0000-000000000000", - expectedCount: 0, + name: "invalid library_id", + query: "Harry", + libraryID: "00000000-0000-0000-0000-000000000000", + expectedStatus: http.StatusNotFound, }, } @@ -435,10 +436,9 @@ func TestCollectionSearchLibraryFilter(t *testing.T) { _ = Body.Close() }(resp.Body) - // Log response for debugging - if resp.StatusCode != http.StatusOK { - bodyBytes, _ := io.ReadAll(resp.Body) - t.Logf("ERROR %d: %s", resp.StatusCode, string(bodyBytes)) + if tt.expectedStatus != 0 { + require.Equal(t, tt.expectedStatus, resp.StatusCode) + return } var result []map[string]interface{}