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).
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user