navidrome/tests/mock_library_repo.go
Deluan d5c598d94a refactor test helpers
Signed-off-by: Deluan <deluan@navidrome.org>
2025-03-30 13:43:55 -04:00

38 lines
741 B
Go

package tests
import (
"github.com/navidrome/navidrome/model"
"golang.org/x/exp/maps"
)
type MockLibraryRepo struct {
model.LibraryRepository
Data map[int]model.Library
Err error
}
func (m *MockLibraryRepo) SetData(data model.Libraries) {
m.Data = make(map[int]model.Library)
for _, d := range data {
m.Data[d.ID] = d
}
}
func (m *MockLibraryRepo) GetAll(...model.QueryOptions) (model.Libraries, error) {
if m.Err != nil {
return nil, m.Err
}
return maps.Values(m.Data), nil
}
func (m *MockLibraryRepo) GetPath(id int) (string, error) {
if m.Err != nil {
return "", m.Err
}
if lib, ok := m.Data[id]; ok {
return lib.Path, nil
}
return "", model.ErrNotFound
}
var _ model.LibraryRepository = &MockLibraryRepo{}