diff --git a/core/mock_user_service.go b/core/mock_user_service.go deleted file mode 100644 index 132eaff6a..000000000 --- a/core/mock_user_service.go +++ /dev/null @@ -1,55 +0,0 @@ -package core - -import ( - "context" - - "github.com/deluan/rest" - "github.com/navidrome/navidrome/model" - "github.com/navidrome/navidrome/tests" -) - -// MockUserWrapper provides a simple wrapper around MockedUserRepo -// that implements the core.User interface for testing -type MockUserWrapper struct { - *tests.MockedUserRepo -} - -// MockUserRestAdapter adapts MockedUserRepo to rest.Repository interface -type MockUserRestAdapter struct { - *tests.MockedUserRepo -} - -// NewMockUserService creates a new mock user service for testing -func NewMockUserService() User { - repo := tests.CreateMockUserRepo() - return &MockUserWrapper{MockedUserRepo: repo} -} - -func (m *MockUserWrapper) NewRepository(ctx context.Context) rest.Repository { - return &MockUserRestAdapter{MockedUserRepo: m.MockedUserRepo} -} - -// rest.Repository interface implementation - -func (a *MockUserRestAdapter) Count(options ...rest.QueryOptions) (int64, error) { - return a.CountAll() -} - -func (a *MockUserRestAdapter) Read(id string) (interface{}, error) { - return a.Get(id) -} - -func (a *MockUserRestAdapter) ReadAll(options ...rest.QueryOptions) (interface{}, error) { - return a.GetAll() -} - -func (a *MockUserRestAdapter) EntityName() string { - return "user" -} - -func (a *MockUserRestAdapter) NewInstance() interface{} { - return &model.User{} -} - -var _ User = (*MockUserWrapper)(nil) -var _ rest.Repository = (*MockUserRestAdapter)(nil) diff --git a/server/nativeapi/config_test.go b/server/nativeapi/config_test.go index 20002cba5..3b4e331ab 100644 --- a/server/nativeapi/config_test.go +++ b/server/nativeapi/config_test.go @@ -10,7 +10,6 @@ import ( "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/conf/configtest" "github.com/navidrome/navidrome/consts" - "github.com/navidrome/navidrome/core" "github.com/navidrome/navidrome/core/auth" "github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/server" @@ -29,7 +28,7 @@ var _ = Describe("Config API", func() { conf.Server.DevUIShowConfig = true // Enable config endpoint for tests ds = &tests.MockDataStore{} auth.Init(ds) - nativeRouter := New(ds, nil, nil, nil, core.NewMockLibraryService(), core.NewMockUserService(), nil, nil) + nativeRouter := New(ds, nil, nil, nil, tests.NewMockLibraryService(), tests.NewMockUserService(), nil, nil) router = server.JWTVerifier(nativeRouter) // Create test users diff --git a/server/nativeapi/library_test.go b/server/nativeapi/library_test.go index 791718115..5b9cf7e4e 100644 --- a/server/nativeapi/library_test.go +++ b/server/nativeapi/library_test.go @@ -11,7 +11,6 @@ import ( "github.com/navidrome/navidrome/conf/configtest" "github.com/navidrome/navidrome/consts" - "github.com/navidrome/navidrome/core" "github.com/navidrome/navidrome/core/auth" "github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/server" @@ -30,7 +29,7 @@ var _ = Describe("Library API", func() { DeferCleanup(configtest.SetupConfig()) ds = &tests.MockDataStore{} auth.Init(ds) - nativeRouter := New(ds, nil, nil, nil, core.NewMockLibraryService(), core.NewMockUserService(), nil, nil) + nativeRouter := New(ds, nil, nil, nil, tests.NewMockLibraryService(), tests.NewMockUserService(), nil, nil) router = server.JWTVerifier(nativeRouter) // Create test users diff --git a/server/nativeapi/native_api_song_test.go b/server/nativeapi/native_api_song_test.go index 254777858..b192e00ac 100644 --- a/server/nativeapi/native_api_song_test.go +++ b/server/nativeapi/native_api_song_test.go @@ -11,7 +11,6 @@ import ( "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/conf/configtest" "github.com/navidrome/navidrome/consts" - "github.com/navidrome/navidrome/core" "github.com/navidrome/navidrome/core/auth" "github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/server" @@ -95,7 +94,7 @@ var _ = Describe("Song Endpoints", func() { mfRepo.SetData(testSongs) // Create the native API router and wrap it with the JWTVerifier middleware - nativeRouter := New(ds, nil, nil, nil, core.NewMockLibraryService(), core.NewMockUserService(), nil, nil) + nativeRouter := New(ds, nil, nil, nil, tests.NewMockLibraryService(), tests.NewMockUserService(), nil, nil) router = server.JWTVerifier(nativeRouter) w = httptest.NewRecorder() }) diff --git a/server/nativeapi/plugin_test.go b/server/nativeapi/plugin_test.go index 067c10e34..7946b90fd 100644 --- a/server/nativeapi/plugin_test.go +++ b/server/nativeapi/plugin_test.go @@ -11,7 +11,6 @@ import ( "github.com/navidrome/navidrome/conf" "github.com/navidrome/navidrome/conf/configtest" "github.com/navidrome/navidrome/consts" - "github.com/navidrome/navidrome/core" "github.com/navidrome/navidrome/core/auth" "github.com/navidrome/navidrome/model" "github.com/navidrome/navidrome/model/request" @@ -34,7 +33,7 @@ var _ = Describe("Plugin API", func() { ds = &tests.MockDataStore{} mockManager = &tests.MockPluginManager{} auth.Init(ds) - nativeRouter := New(ds, nil, nil, nil, core.NewMockLibraryService(), core.NewMockUserService(), nil, mockManager) + nativeRouter := New(ds, nil, nil, nil, tests.NewMockLibraryService(), tests.NewMockUserService(), nil, mockManager) router = server.JWTVerifier(nativeRouter) // Create test users diff --git a/core/mock_library_service.go b/tests/mock_library_service.go similarity index 57% rename from core/mock_library_service.go rename to tests/mock_library_service.go index 56f2abd4c..78693197d 100644 --- a/core/mock_library_service.go +++ b/tests/mock_library_service.go @@ -1,27 +1,28 @@ -package core +package tests import ( "context" "github.com/deluan/rest" "github.com/navidrome/navidrome/model" - "github.com/navidrome/navidrome/tests" ) -// MockLibraryWrapper provides a simple wrapper around MockLibraryRepo -// that implements the core.Library interface for testing -type MockLibraryWrapper struct { - *tests.MockLibraryRepo +// MockLibraryService provides a simple wrapper around MockLibraryRepo +// that implements the core.Library interface for testing. +// Returns concrete type to avoid import cycles - callers assign to core.Library. +type MockLibraryService struct { + *MockLibraryRepo } // MockLibraryRestAdapter adapts MockLibraryRepo to rest.Repository interface type MockLibraryRestAdapter struct { - *tests.MockLibraryRepo + *MockLibraryRepo } -// NewMockLibraryService creates a new mock library service for testing -func NewMockLibraryService() Library { - repo := &tests.MockLibraryRepo{ +// NewMockLibraryService creates a new mock library service for testing. +// Returns concrete type - assign to core.Library at call site. +func NewMockLibraryService() *MockLibraryService { + repo := &MockLibraryRepo{ Data: make(map[int]model.Library), } // Set up default test data @@ -29,10 +30,10 @@ func NewMockLibraryService() Library { {ID: 1, Name: "Test Library 1", Path: "/music/library1"}, {ID: 2, Name: "Test Library 2", Path: "/music/library2"}, }) - return &MockLibraryWrapper{MockLibraryRepo: repo} + return &MockLibraryService{MockLibraryRepo: repo} } -func (m *MockLibraryWrapper) NewRepository(ctx context.Context) rest.Repository { +func (m *MockLibraryService) NewRepository(ctx context.Context) rest.Repository { return &MockLibraryRestAdapter{MockLibraryRepo: m.MockLibraryRepo} } @@ -41,6 +42,3 @@ func (m *MockLibraryWrapper) NewRepository(ctx context.Context) rest.Repository func (a *MockLibraryRestAdapter) Delete(id string) error { return a.DeleteByStringID(id) } - -var _ Library = (*MockLibraryWrapper)(nil) -var _ rest.Repository = (*MockLibraryRestAdapter)(nil) diff --git a/tests/mock_user_service.go b/tests/mock_user_service.go new file mode 100644 index 000000000..f2700de45 --- /dev/null +++ b/tests/mock_user_service.go @@ -0,0 +1,30 @@ +package tests + +import ( + "context" + + "github.com/deluan/rest" +) + +// MockUserService provides a simple wrapper around MockedUserRepo +// that implements the core.User interface for testing. +// Returns concrete type to avoid import cycles - callers assign to core.User. +type MockUserService struct { + *MockedUserRepo +} + +// MockUserRestAdapter adapts MockedUserRepo to rest.Repository interface +type MockUserRestAdapter struct { + *MockedUserRepo +} + +// NewMockUserService creates a new mock user service for testing. +// Returns concrete type - assign to core.User at call site. +func NewMockUserService() *MockUserService { + repo := CreateMockUserRepo() + return &MockUserService{MockedUserRepo: repo} +} + +func (m *MockUserService) NewRepository(ctx context.Context) rest.Repository { + return &MockUserRestAdapter{MockedUserRepo: m.MockedUserRepo} +}