navidrome/tests/mock_library_repo.go
Deluan Quintão 5667f6ab75
feat(scanner): add library stats to DB (#4229)
* Combine library stats migrations

* test: verify full library stats

* Fix total_songs calculation

* Fix library stats migration

* fix(scanner): log elapsed time and number of libraries updated during scan

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(scanner): refresh library stats conditionally, only if changes were detected

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(scanner): refresh library stats conditionally, only if changes were detected

Signed-off-by: Deluan <deluan@navidrome.org>

* fix(scanner): update queries to exclude missing entries in library stats

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
2025-06-14 15:58:33 -04:00

43 lines
811 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
}
func (m *MockLibraryRepo) RefreshStats(id int) error {
return nil
}
var _ model.LibraryRepository = &MockLibraryRepo{}