navidrome/tests/mock_artist_repo.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
874 B
Go
Raw Normal View History

2020-10-27 16:01:40 +01:00
package tests
import (
2016-03-03 06:46:23 +01:00
"errors"
2020-01-24 01:44:08 +01:00
"github.com/navidrome/navidrome/model"
)
2021-06-08 22:30:19 +02:00
func CreateMockArtistRepo() *MockArtistRepo {
return &MockArtistRepo{}
}
2021-06-08 22:30:19 +02:00
type MockArtistRepo struct {
2020-01-15 04:22:34 +01:00
model.ArtistRepository
2020-04-09 18:13:54 +02:00
data map[string]model.Artist
err bool
}
2021-06-08 22:30:19 +02:00
func (m *MockArtistRepo) SetError(err bool) {
m.err = err
}
2021-06-08 22:30:19 +02:00
func (m *MockArtistRepo) SetData(artists model.Artists) {
2020-04-09 18:13:54 +02:00
m.data = make(map[string]model.Artist)
2020-10-27 15:48:37 +01:00
for _, a := range artists {
2020-04-09 18:13:54 +02:00
m.data[a.ID] = a
2016-03-03 02:50:16 +01:00
}
}
2021-06-08 22:30:19 +02:00
func (m *MockArtistRepo) Exists(id string) (bool, error) {
2020-04-09 18:13:54 +02:00
if m.err {
return false, errors.New("Error!")
}
2016-03-03 06:46:23 +01:00
_, found := m.data[id]
return found, nil
2016-03-03 02:50:16 +01:00
}
2021-06-08 22:30:19 +02:00
func (m *MockArtistRepo) Get(id string) (*model.Artist, error) {
2016-03-03 02:50:16 +01:00
if m.err {
return nil, errors.New("Error!")
}
if d, ok := m.data[id]; ok {
2020-04-09 18:13:54 +02:00
return &d, nil
}
2020-01-15 04:22:34 +01:00
return nil, model.ErrNotFound
2016-03-03 06:46:23 +01:00
}
2021-06-08 22:30:19 +02:00
var _ model.ArtistRepository = (*MockArtistRepo)(nil)