mirror of
https://github.com/navidrome/navidrome.git
synced 2025-07-14 07:31:28 +03:00
* 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>
43 lines
811 B
Go
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{}
|