From c016a4582bca4b7e47d5af35b83669b9ef3a859d Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Sat, 7 Feb 2026 21:48:07 -0500 Subject: [PATCH] fix(tests): initialize missing handlers in test setup Fix nil pointer panics in integration tests by initializing the four refactored handlers (MediaHandler, SearchHandler, MatchingHandler, CollectionHandler) that were added during Phase 6 refactoring but never added to the test setup. These handlers were properly instantiated in cmd/server/main.go (commit 9fd8a39) but were missing from cmd/server/tests/test_helpers.go, causing panics when tests tried to use /api/collections and /api/media-items endpoints. Changes: - Create worker with 3 concurrent workers - Initialize CollectionHandler with queries and connManager - Initialize MediaHandler with queries and worker - Initialize SearchHandler with queries - Initialize MatchingHandler with queries and connManager - Add all four handlers to router.Config struct Fixes panic errors: - internal/handlers/collections.go:78 (CreateCollection nil pointer) - internal/handlers/media.go:891 (CreateMediaItem nil pointer) Tests now pass: - TestCollectionsBulkOperations: PASS - TestAnalytics*: PASS (all analytics tests) Note: Bruno API tests and frontend were NOT affected as they use the real running application (which has complete handler setup). --- cmd/server/tests/test_helpers.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/server/tests/test_helpers.go b/cmd/server/tests/test_helpers.go index 9f08707..7f316e5 100644 --- a/cmd/server/tests/test_helpers.go +++ b/cmd/server/tests/test_helpers.go @@ -144,6 +144,13 @@ func setupTestServer(t *testing.T) (*httptest.Server, *database.Queries, *config analyticsHandler := handlers.NewAnalyticsHandler(queries) queueHandler := handlers.NewQueueHandler(queries, queueProcessor) + // Create refactored handlers (matching main.go Phase 6) + worker := services.NewWorker(3) + collectionHandler := handlers.NewCollectionHandler(queries, connManager) + mediaHandler := handlers.NewMediaHandler(queries, worker) + searchHandler := handlers.NewSearchHandler(queries) + matchingHandler := handlers.NewMatchingHandler(queries, connManager) + // Create conversion service for OPDS conversionService := services.NewConversionService(queries, getCachePath()) opdsHandler := handlers.NewOPDSHandler(queries, conversionService) @@ -172,11 +179,15 @@ func setupTestServer(t *testing.T) (*httptest.Server, *database.Queries, *config AuthHandler: authHandler, LibraryHandler: libraryHandler, DeviceHandler: deviceHandler, + MediaHandler: mediaHandler, + SearchHandler: searchHandler, + MatchingHandler: matchingHandler, KOReaderHandler: koreaderHandler, WSHandler: wsHandler, ConflictHandler: conflictHandler, AnalyticsHandler: analyticsHandler, QueueHandler: queueHandler, + CollectionHandler: collectionHandler, OPDSHandler: opdsHandler, ConnManager: connManager, QueueProcessor: queueProcessor,