mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-23 23:20:57 +03:00
refactor test helpers
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
244db3419a
commit
d5c598d94a
@ -84,12 +84,12 @@ type testArtistRepo struct {
|
||||
|
||||
func (m *testArtistRepo) GetAll(options ...model.QueryOptions) (model.Artists, error) {
|
||||
// Get the error state using reflection
|
||||
if getField(m.MockArtistRepo, "err").(bool) {
|
||||
if getField(m.MockArtistRepo, "Err").(bool) {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
|
||||
// Get the data using reflection
|
||||
dataMap := getField(m.MockArtistRepo, "data").(map[string]*model.Artist)
|
||||
dataMap := getField(m.MockArtistRepo, "Data").(map[string]*model.Artist)
|
||||
|
||||
// Convert map to slice
|
||||
artists := make(model.Artists, 0, len(dataMap))
|
||||
@ -145,12 +145,12 @@ type testMediaFileRepo struct {
|
||||
|
||||
func (m *testMediaFileRepo) GetAll(options ...model.QueryOptions) (model.MediaFiles, error) {
|
||||
// Get the error state using reflection
|
||||
if getField(m.MockMediaFileRepo, "err").(bool) {
|
||||
if getField(m.MockMediaFileRepo, "Err").(bool) {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
|
||||
// Get the data using reflection
|
||||
dataMap := getField(m.MockMediaFileRepo, "data").(map[string]*model.MediaFile)
|
||||
dataMap := getField(m.MockMediaFileRepo, "Data").(map[string]*model.MediaFile)
|
||||
|
||||
// Convert map to slice
|
||||
mediaFiles := make(model.MediaFiles, 0, len(dataMap))
|
||||
|
@ -10,56 +10,56 @@ import (
|
||||
|
||||
func CreateMockAlbumRepo() *MockAlbumRepo {
|
||||
return &MockAlbumRepo{
|
||||
data: make(map[string]*model.Album),
|
||||
Data: make(map[string]*model.Album),
|
||||
}
|
||||
}
|
||||
|
||||
type MockAlbumRepo struct {
|
||||
model.AlbumRepository
|
||||
data map[string]*model.Album
|
||||
all model.Albums
|
||||
err bool
|
||||
Data map[string]*model.Album
|
||||
All model.Albums
|
||||
Err bool
|
||||
Options model.QueryOptions
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) SetError(err bool) {
|
||||
m.err = err
|
||||
m.Err = err
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) SetData(albums model.Albums) {
|
||||
m.data = make(map[string]*model.Album, len(albums))
|
||||
m.all = albums
|
||||
for i, a := range m.all {
|
||||
m.data[a.ID] = &m.all[i]
|
||||
m.Data = make(map[string]*model.Album, len(albums))
|
||||
m.All = albums
|
||||
for i, a := range m.All {
|
||||
m.Data[a.ID] = &m.All[i]
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) Exists(id string) (bool, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return false, errors.New("unexpected error")
|
||||
}
|
||||
_, found := m.data[id]
|
||||
_, found := m.Data[id]
|
||||
return found, nil
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) Get(id string) (*model.Album, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("unexpected error")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
return d, nil
|
||||
}
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) Put(al *model.Album) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("unexpected error")
|
||||
}
|
||||
if al.ID == "" {
|
||||
al.ID = id.NewRandom()
|
||||
}
|
||||
m.data[al.ID] = al
|
||||
m.Data[al.ID] = al
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -67,17 +67,17 @@ func (m *MockAlbumRepo) GetAll(qo ...model.QueryOptions) (model.Albums, error) {
|
||||
if len(qo) > 0 {
|
||||
m.Options = qo[0]
|
||||
}
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("unexpected error")
|
||||
}
|
||||
return m.all, nil
|
||||
return m.All, nil
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) IncPlayCount(id string, timestamp time.Time) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("unexpected error")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
d.PlayCount++
|
||||
d.PlayDate = ×tamp
|
||||
return nil
|
||||
@ -85,15 +85,15 @@ func (m *MockAlbumRepo) IncPlayCount(id string, timestamp time.Time) error {
|
||||
return model.ErrNotFound
|
||||
}
|
||||
func (m *MockAlbumRepo) CountAll(...model.QueryOptions) (int64, error) {
|
||||
return int64(len(m.all)), nil
|
||||
return int64(len(m.All)), nil
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) GetTouchedAlbums(libID int) (model.AlbumCursor, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("unexpected error")
|
||||
}
|
||||
return func(yield func(model.Album, error) bool) {
|
||||
for _, a := range m.data {
|
||||
for _, a := range m.Data {
|
||||
if a.ID == "error" {
|
||||
if !yield(*a, errors.New("error")) {
|
||||
break
|
||||
|
@ -10,61 +10,61 @@ import (
|
||||
|
||||
func CreateMockArtistRepo() *MockArtistRepo {
|
||||
return &MockArtistRepo{
|
||||
data: make(map[string]*model.Artist),
|
||||
Data: make(map[string]*model.Artist),
|
||||
}
|
||||
}
|
||||
|
||||
type MockArtistRepo struct {
|
||||
model.ArtistRepository
|
||||
data map[string]*model.Artist
|
||||
err bool
|
||||
Data map[string]*model.Artist
|
||||
Err bool
|
||||
}
|
||||
|
||||
func (m *MockArtistRepo) SetError(err bool) {
|
||||
m.err = err
|
||||
m.Err = err
|
||||
}
|
||||
|
||||
func (m *MockArtistRepo) SetData(artists model.Artists) {
|
||||
m.data = make(map[string]*model.Artist)
|
||||
m.Data = make(map[string]*model.Artist)
|
||||
for i, a := range artists {
|
||||
m.data[a.ID] = &artists[i]
|
||||
m.Data[a.ID] = &artists[i]
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockArtistRepo) Exists(id string) (bool, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return false, errors.New("Error!")
|
||||
}
|
||||
_, found := m.data[id]
|
||||
_, found := m.Data[id]
|
||||
return found, nil
|
||||
}
|
||||
|
||||
func (m *MockArtistRepo) Get(id string) (*model.Artist, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
return d, nil
|
||||
}
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *MockArtistRepo) Put(ar *model.Artist, columsToUpdate ...string) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
if ar.ID == "" {
|
||||
ar.ID = id.NewRandom()
|
||||
}
|
||||
m.data[ar.ID] = ar
|
||||
m.Data[ar.ID] = ar
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockArtistRepo) IncPlayCount(id string, timestamp time.Time) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
d.PlayCount++
|
||||
d.PlayDate = ×tamp
|
||||
return nil
|
||||
|
@ -6,12 +6,12 @@ import (
|
||||
|
||||
type MockedGenreRepo struct {
|
||||
Error error
|
||||
data map[string]model.Genre
|
||||
Data map[string]model.Genre
|
||||
}
|
||||
|
||||
func (r *MockedGenreRepo) init() {
|
||||
if r.data == nil {
|
||||
r.data = make(map[string]model.Genre)
|
||||
if r.Data == nil {
|
||||
r.Data = make(map[string]model.Genre)
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ func (r *MockedGenreRepo) GetAll(...model.QueryOptions) (model.Genres, error) {
|
||||
r.init()
|
||||
|
||||
var all model.Genres
|
||||
for _, g := range r.data {
|
||||
for _, g := range r.Data {
|
||||
all = append(all, g)
|
||||
}
|
||||
return all, nil
|
||||
@ -33,6 +33,6 @@ func (r *MockedGenreRepo) Put(g *model.Genre) error {
|
||||
return r.Error
|
||||
}
|
||||
r.init()
|
||||
r.data[g.ID] = *g
|
||||
r.Data[g.ID] = *g
|
||||
return nil
|
||||
}
|
||||
|
@ -7,14 +7,14 @@ import (
|
||||
|
||||
type MockLibraryRepo struct {
|
||||
model.LibraryRepository
|
||||
data map[int]model.Library
|
||||
Data map[int]model.Library
|
||||
Err error
|
||||
}
|
||||
|
||||
func (m *MockLibraryRepo) SetData(data model.Libraries) {
|
||||
m.data = make(map[int]model.Library)
|
||||
m.Data = make(map[int]model.Library)
|
||||
for _, d := range data {
|
||||
m.data[d.ID] = d
|
||||
m.Data[d.ID] = d
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,14 +22,14 @@ func (m *MockLibraryRepo) GetAll(...model.QueryOptions) (model.Libraries, error)
|
||||
if m.Err != nil {
|
||||
return nil, m.Err
|
||||
}
|
||||
return maps.Values(m.data), nil
|
||||
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 {
|
||||
if lib, ok := m.Data[id]; ok {
|
||||
return lib.Path, nil
|
||||
}
|
||||
return "", model.ErrNotFound
|
||||
|
@ -14,40 +14,40 @@ import (
|
||||
|
||||
func CreateMockMediaFileRepo() *MockMediaFileRepo {
|
||||
return &MockMediaFileRepo{
|
||||
data: make(map[string]*model.MediaFile),
|
||||
Data: make(map[string]*model.MediaFile),
|
||||
}
|
||||
}
|
||||
|
||||
type MockMediaFileRepo struct {
|
||||
model.MediaFileRepository
|
||||
data map[string]*model.MediaFile
|
||||
err bool
|
||||
Data map[string]*model.MediaFile
|
||||
Err bool
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) SetError(err bool) {
|
||||
m.err = err
|
||||
m.Err = err
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) SetData(mfs model.MediaFiles) {
|
||||
m.data = make(map[string]*model.MediaFile)
|
||||
m.Data = make(map[string]*model.MediaFile)
|
||||
for i, mf := range mfs {
|
||||
m.data[mf.ID] = &mfs[i]
|
||||
m.Data[mf.ID] = &mfs[i]
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) Exists(id string) (bool, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return false, errors.New("error")
|
||||
}
|
||||
_, found := m.data[id]
|
||||
_, found := m.Data[id]
|
||||
return found, nil
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) Get(id string) (*model.MediaFile, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
// Intentionally clone the file and remove participants. This should
|
||||
// catch any caller that actually means to call GetWithParticipants
|
||||
res := *d
|
||||
@ -58,52 +58,52 @@ func (m *MockMediaFileRepo) Get(id string) (*model.MediaFile, error) {
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) GetWithParticipants(id string) (*model.MediaFile, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
return d, nil
|
||||
}
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) GetAll(...model.QueryOptions) (model.MediaFiles, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
values := slices.Collect(maps.Values(m.data))
|
||||
values := slices.Collect(maps.Values(m.Data))
|
||||
return slice.Map(values, func(p *model.MediaFile) model.MediaFile {
|
||||
return *p
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) Put(mf *model.MediaFile) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
if mf.ID == "" {
|
||||
mf.ID = id.NewRandom()
|
||||
}
|
||||
m.data[mf.ID] = mf
|
||||
m.Data[mf.ID] = mf
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) Delete(id string) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
if _, ok := m.data[id]; !ok {
|
||||
if _, ok := m.Data[id]; !ok {
|
||||
return model.ErrNotFound
|
||||
}
|
||||
delete(m.data, id)
|
||||
delete(m.Data, id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) IncPlayCount(id string, timestamp time.Time) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
d.PlayCount++
|
||||
d.PlayDate = ×tamp
|
||||
return nil
|
||||
@ -112,12 +112,12 @@ func (m *MockMediaFileRepo) IncPlayCount(id string, timestamp time.Time) error {
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) FindByAlbum(artistId string) (model.MediaFiles, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
var res = make(model.MediaFiles, len(m.data))
|
||||
var res = make(model.MediaFiles, len(m.Data))
|
||||
i := 0
|
||||
for _, a := range m.data {
|
||||
for _, a := range m.Data {
|
||||
if a.AlbumID == artistId {
|
||||
res[i] = *a
|
||||
i++
|
||||
@ -128,17 +128,17 @@ func (m *MockMediaFileRepo) FindByAlbum(artistId string) (model.MediaFiles, erro
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) GetMissingAndMatching(libId int) (model.MediaFileCursor, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
var res model.MediaFiles
|
||||
for _, a := range m.data {
|
||||
for _, a := range m.Data {
|
||||
if a.LibraryID == libId && a.Missing {
|
||||
res = append(res, *a)
|
||||
}
|
||||
}
|
||||
|
||||
for _, a := range m.data {
|
||||
for _, a := range m.Data {
|
||||
if a.LibraryID == libId && !(*a).Missing && slices.IndexFunc(res, func(mediaFile model.MediaFile) bool {
|
||||
return mediaFile.PID == a.PID
|
||||
}) != -1 {
|
||||
|
@ -5,12 +5,12 @@ import "github.com/navidrome/navidrome/model"
|
||||
type MockedPropertyRepo struct {
|
||||
model.PropertyRepository
|
||||
Error error
|
||||
data map[string]string
|
||||
Data map[string]string
|
||||
}
|
||||
|
||||
func (p *MockedPropertyRepo) init() {
|
||||
if p.data == nil {
|
||||
p.data = make(map[string]string)
|
||||
if p.Data == nil {
|
||||
p.Data = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ func (p *MockedPropertyRepo) Put(id string, value string) error {
|
||||
return p.Error
|
||||
}
|
||||
p.init()
|
||||
p.data[id] = value
|
||||
p.Data[id] = value
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ func (p *MockedPropertyRepo) Get(id string) (string, error) {
|
||||
return "", p.Error
|
||||
}
|
||||
p.init()
|
||||
if v, ok := p.data[id]; ok {
|
||||
if v, ok := p.Data[id]; ok {
|
||||
return v, nil
|
||||
}
|
||||
return "", model.ErrNotFound
|
||||
@ -39,8 +39,8 @@ func (p *MockedPropertyRepo) Delete(id string) error {
|
||||
return p.Error
|
||||
}
|
||||
p.init()
|
||||
if _, ok := p.data[id]; ok {
|
||||
delete(p.data, id)
|
||||
if _, ok := p.Data[id]; ok {
|
||||
delete(p.Data, id)
|
||||
return nil
|
||||
}
|
||||
return model.ErrNotFound
|
||||
|
@ -9,9 +9,9 @@ import (
|
||||
|
||||
type MockedRadioRepo struct {
|
||||
model.RadioRepository
|
||||
data map[string]*model.Radio
|
||||
all model.Radios
|
||||
err bool
|
||||
Data map[string]*model.Radio
|
||||
All model.Radios
|
||||
Err bool
|
||||
Options model.QueryOptions
|
||||
}
|
||||
|
||||
@ -20,44 +20,44 @@ func CreateMockedRadioRepo() *MockedRadioRepo {
|
||||
}
|
||||
|
||||
func (m *MockedRadioRepo) SetError(err bool) {
|
||||
m.err = err
|
||||
m.Err = err
|
||||
}
|
||||
|
||||
func (m *MockedRadioRepo) CountAll(options ...model.QueryOptions) (int64, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return 0, errors.New("error")
|
||||
}
|
||||
return int64(len(m.data)), nil
|
||||
return int64(len(m.Data)), nil
|
||||
}
|
||||
|
||||
func (m *MockedRadioRepo) Delete(id string) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("Error!")
|
||||
}
|
||||
|
||||
_, found := m.data[id]
|
||||
_, found := m.Data[id]
|
||||
|
||||
if !found {
|
||||
return errors.New("not found")
|
||||
}
|
||||
|
||||
delete(m.data, id)
|
||||
delete(m.Data, id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockedRadioRepo) Exists(id string) (bool, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return false, errors.New("Error!")
|
||||
}
|
||||
_, found := m.data[id]
|
||||
_, found := m.Data[id]
|
||||
return found, nil
|
||||
}
|
||||
|
||||
func (m *MockedRadioRepo) Get(id string) (*model.Radio, error) {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
if d, ok := m.Data[id]; ok {
|
||||
return d, nil
|
||||
}
|
||||
return nil, model.ErrNotFound
|
||||
@ -67,19 +67,19 @@ func (m *MockedRadioRepo) GetAll(qo ...model.QueryOptions) (model.Radios, error)
|
||||
if len(qo) > 0 {
|
||||
m.Options = qo[0]
|
||||
}
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
return m.all, nil
|
||||
return m.All, nil
|
||||
}
|
||||
|
||||
func (m *MockedRadioRepo) Put(radio *model.Radio) error {
|
||||
if m.err {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
if radio.ID == "" {
|
||||
radio.ID = id.NewRandom()
|
||||
}
|
||||
m.data[radio.ID] = radio
|
||||
m.Data[radio.ID] = radio
|
||||
return nil
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
type MockedScrobbleBufferRepo struct {
|
||||
Error error
|
||||
data model.ScrobbleEntries
|
||||
Data model.ScrobbleEntries
|
||||
}
|
||||
|
||||
func CreateMockedScrobbleBufferRepo() *MockedScrobbleBufferRepo {
|
||||
@ -20,7 +20,7 @@ func (m *MockedScrobbleBufferRepo) UserIDs(service string) ([]string, error) {
|
||||
return nil, m.Error
|
||||
}
|
||||
userIds := make(map[string]struct{})
|
||||
for _, e := range m.data {
|
||||
for _, e := range m.Data {
|
||||
if e.Service == service {
|
||||
userIds[e.UserID] = struct{}{}
|
||||
}
|
||||
@ -36,7 +36,7 @@ func (m *MockedScrobbleBufferRepo) Enqueue(service, userId, mediaFileId string,
|
||||
if m.Error != nil {
|
||||
return m.Error
|
||||
}
|
||||
m.data = append(m.data, model.ScrobbleEntry{
|
||||
m.Data = append(m.Data, model.ScrobbleEntry{
|
||||
MediaFile: model.MediaFile{ID: mediaFileId},
|
||||
Service: service,
|
||||
UserID: userId,
|
||||
@ -50,7 +50,7 @@ func (m *MockedScrobbleBufferRepo) Next(service, userId string) (*model.Scrobble
|
||||
if m.Error != nil {
|
||||
return nil, m.Error
|
||||
}
|
||||
for _, e := range m.data {
|
||||
for _, e := range m.Data {
|
||||
if e.Service == service && e.UserID == userId {
|
||||
return &e, nil
|
||||
}
|
||||
@ -63,13 +63,13 @@ func (m *MockedScrobbleBufferRepo) Dequeue(entry *model.ScrobbleEntry) error {
|
||||
return m.Error
|
||||
}
|
||||
newData := model.ScrobbleEntries{}
|
||||
for _, e := range m.data {
|
||||
for _, e := range m.Data {
|
||||
if e.Service == entry.Service && e.UserID == entry.UserID && e.PlayTime == entry.PlayTime && e.MediaFile.ID == entry.MediaFile.ID {
|
||||
continue
|
||||
}
|
||||
newData = append(newData, e)
|
||||
}
|
||||
m.data = newData
|
||||
m.Data = newData
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -77,5 +77,5 @@ func (m *MockedScrobbleBufferRepo) Length() (int64, error) {
|
||||
if m.Error != nil {
|
||||
return 0, m.Error
|
||||
}
|
||||
return int64(len(m.data)), nil
|
||||
return int64(len(m.Data)), nil
|
||||
}
|
||||
|
@ -5,12 +5,12 @@ import "github.com/navidrome/navidrome/model"
|
||||
type MockedUserPropsRepo struct {
|
||||
model.UserPropsRepository
|
||||
Error error
|
||||
data map[string]string
|
||||
Data map[string]string
|
||||
}
|
||||
|
||||
func (p *MockedUserPropsRepo) init() {
|
||||
if p.data == nil {
|
||||
p.data = make(map[string]string)
|
||||
if p.Data == nil {
|
||||
p.Data = make(map[string]string)
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ func (p *MockedUserPropsRepo) Put(userId, key string, value string) error {
|
||||
return p.Error
|
||||
}
|
||||
p.init()
|
||||
p.data[userId+key] = value
|
||||
p.Data[userId+key] = value
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ func (p *MockedUserPropsRepo) Get(userId, key string) (string, error) {
|
||||
return "", p.Error
|
||||
}
|
||||
p.init()
|
||||
if v, ok := p.data[userId+key]; ok {
|
||||
if v, ok := p.Data[userId+key]; ok {
|
||||
return v, nil
|
||||
}
|
||||
return "", model.ErrNotFound
|
||||
@ -39,8 +39,8 @@ func (p *MockedUserPropsRepo) Delete(userId, key string) error {
|
||||
return p.Error
|
||||
}
|
||||
p.init()
|
||||
if _, ok := p.data[userId+key]; ok {
|
||||
delete(p.data, userId+key)
|
||||
if _, ok := p.Data[userId+key]; ok {
|
||||
delete(p.Data, userId+key)
|
||||
return nil
|
||||
}
|
||||
return model.ErrNotFound
|
||||
|
Loading…
x
Reference in New Issue
Block a user