Files
navidrome/tests/mock_playlist_repo.go
T
Deluan b64d8ad334 fix(server): return 404 instead of 500 for non-existent playlists
The native API endpoints GET /playlist/{id}/tracks and
GET /playlist/{id}/tracks/{id} were panicking with a nil pointer
dereference (resulting in a 500) when the playlist did not exist.
This happened because Tracks() returns nil for missing playlists,
and the nil repository was passed directly to the rest handler.
Extracted a shared playlistTracksHandler that checks for nil and
returns 404 early. Added tests covering both the error and happy paths.
2026-02-15 22:39:27 -05:00

39 lines
730 B
Go

package tests
import (
"github.com/deluan/rest"
"github.com/navidrome/navidrome/model"
)
type MockPlaylistRepo struct {
model.PlaylistRepository
Entity *model.Playlist
Error error
TracksReturn model.PlaylistTrackRepository
}
func (m *MockPlaylistRepo) Get(_ string) (*model.Playlist, error) {
if m.Error != nil {
return nil, m.Error
}
if m.Entity == nil {
return nil, model.ErrNotFound
}
return m.Entity, nil
}
func (m *MockPlaylistRepo) Tracks(_ string, _ bool) model.PlaylistTrackRepository {
return m.TracksReturn
}
func (m *MockPlaylistRepo) Count(_ ...rest.QueryOptions) (int64, error) {
if m.Error != nil {
return 0, m.Error
}
if m.Entity == nil {
return 0, nil
}
return 1, nil
}