mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
Make MockRepo names more consistent
This commit is contained in:
parent
779571a086
commit
110e17b004
12 changed files with 79 additions and 47 deletions
|
@ -19,13 +19,13 @@ var _ = Describe("Artwork", func() {
|
||||||
ctx := log.NewContext(context.TODO())
|
ctx := log.NewContext(context.TODO())
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepository{}}
|
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepo{}}
|
||||||
ds.Album(ctx).(*tests.MockAlbum).SetData(model.Albums{
|
ds.Album(ctx).(*tests.MockAlbumRepo).SetData(model.Albums{
|
||||||
{ID: "222", CoverArtId: "123", CoverArtPath: "tests/fixtures/test.mp3"},
|
{ID: "222", CoverArtId: "123", CoverArtPath: "tests/fixtures/test.mp3"},
|
||||||
{ID: "333", CoverArtId: ""},
|
{ID: "333", CoverArtId: ""},
|
||||||
{ID: "444", CoverArtId: "444", CoverArtPath: "tests/fixtures/cover.jpg"},
|
{ID: "444", CoverArtId: "444", CoverArtPath: "tests/fixtures/cover.jpg"},
|
||||||
})
|
})
|
||||||
ds.MediaFile(ctx).(*tests.MockMediaFile).SetData(model.MediaFiles{
|
ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetData(model.MediaFiles{
|
||||||
{ID: "123", AlbumID: "222", Path: "tests/fixtures/test.mp3", HasCoverArt: true},
|
{ID: "123", AlbumID: "222", Path: "tests/fixtures/test.mp3", HasCoverArt: true},
|
||||||
{ID: "456", AlbumID: "222", Path: "tests/fixtures/test.ogg", HasCoverArt: false},
|
{ID: "456", AlbumID: "222", Path: "tests/fixtures/test.ogg", HasCoverArt: false},
|
||||||
})
|
})
|
||||||
|
@ -126,13 +126,13 @@ var _ = Describe("Artwork", func() {
|
||||||
|
|
||||||
Context("Errors", func() {
|
Context("Errors", func() {
|
||||||
It("returns err if gets error from album table", func() {
|
It("returns err if gets error from album table", func() {
|
||||||
ds.Album(ctx).(*tests.MockAlbum).SetError(true)
|
ds.Album(ctx).(*tests.MockAlbumRepo).SetError(true)
|
||||||
_, err := artwork.Get(ctx, "al-222", 0)
|
_, err := artwork.Get(ctx, "al-222", 0)
|
||||||
Expect(err).To(MatchError("Error!"))
|
Expect(err).To(MatchError("Error!"))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns err if gets error from media_file table", func() {
|
It("returns err if gets error from media_file table", func() {
|
||||||
ds.MediaFile(ctx).(*tests.MockMediaFile).SetError(true)
|
ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetError(true)
|
||||||
_, err := artwork.Get(ctx, "123", 0)
|
_, err := artwork.Get(ctx, "123", 0)
|
||||||
Expect(err).To(MatchError("Error!"))
|
Expect(err).To(MatchError("Error!"))
|
||||||
})
|
})
|
||||||
|
|
|
@ -24,8 +24,8 @@ var _ = Describe("MediaStreamer", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
conf.Server.DataFolder, _ = ioutil.TempDir("", "file_caches")
|
conf.Server.DataFolder, _ = ioutil.TempDir("", "file_caches")
|
||||||
conf.Server.TranscodingCacheSize = "100MB"
|
conf.Server.TranscodingCacheSize = "100MB"
|
||||||
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepository{}}
|
ds = &tests.MockDataStore{MockedTranscoding: &tests.MockTranscodingRepo{}}
|
||||||
ds.MediaFile(ctx).(*tests.MockMediaFile).SetData(model.MediaFiles{
|
ds.MediaFile(ctx).(*tests.MockMediaFileRepo).SetData(model.MediaFiles{
|
||||||
{ID: "123", Path: "tests/fixtures/test.mp3", Suffix: "mp3", BitRate: 128, Duration: 257.0},
|
{ID: "123", Path: "tests/fixtures/test.mp3", Suffix: "mp3", BitRate: 128, Duration: 257.0},
|
||||||
})
|
})
|
||||||
testCache := GetTranscodingCache()
|
testCache := GetTranscodingCache()
|
||||||
|
|
|
@ -22,7 +22,7 @@ var _ = Describe("Players", func() {
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
repo = &mockPlayerRepository{}
|
repo = &mockPlayerRepository{}
|
||||||
ds := &tests.MockDataStore{MockedPlayer: repo, MockedTranscoding: &tests.MockTranscodingRepository{}}
|
ds := &tests.MockDataStore{MockedPlayer: repo, MockedTranscoding: &tests.MockTranscodingRepo{}}
|
||||||
players = NewPlayers(ds)
|
players = NewPlayers(ds)
|
||||||
beforeRegister = time.Now()
|
beforeRegister = time.Now()
|
||||||
})
|
})
|
||||||
|
|
|
@ -82,6 +82,8 @@ func (s *SQLStore) Resource(ctx context.Context, m interface{}) model.ResourceRe
|
||||||
return s.MediaFile(ctx).(model.ResourceRepository)
|
return s.MediaFile(ctx).(model.ResourceRepository)
|
||||||
case model.Playlist:
|
case model.Playlist:
|
||||||
return s.Playlist(ctx).(model.ResourceRepository)
|
return s.Playlist(ctx).(model.ResourceRepository)
|
||||||
|
case model.Share:
|
||||||
|
return s.Share(ctx).(model.ResourceRepository)
|
||||||
}
|
}
|
||||||
log.Error("Resource not implemented", "model", reflect.TypeOf(m).Name())
|
log.Error("Resource not implemented", "model", reflect.TypeOf(m).Name())
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -14,13 +14,13 @@ import (
|
||||||
var _ = Describe("AlbumListController", func() {
|
var _ = Describe("AlbumListController", func() {
|
||||||
var controller *AlbumListController
|
var controller *AlbumListController
|
||||||
var ds model.DataStore
|
var ds model.DataStore
|
||||||
var mockRepo *tests.MockAlbum
|
var mockRepo *tests.MockAlbumRepo
|
||||||
var w *httptest.ResponseRecorder
|
var w *httptest.ResponseRecorder
|
||||||
ctx := log.NewContext(context.TODO())
|
ctx := log.NewContext(context.TODO())
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
ds = &tests.MockDataStore{}
|
ds = &tests.MockDataStore{}
|
||||||
mockRepo = ds.Album(ctx).(*tests.MockAlbum)
|
mockRepo = ds.Album(ctx).(*tests.MockAlbumRepo)
|
||||||
controller = NewAlbumListController(ds, nil)
|
controller = NewAlbumListController(ds, nil)
|
||||||
w = httptest.NewRecorder()
|
w = httptest.NewRecorder()
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,11 +6,11 @@ import (
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateMockAlbumRepo() *MockAlbum {
|
func CreateMockAlbumRepo() *MockAlbumRepo {
|
||||||
return &MockAlbum{}
|
return &MockAlbumRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockAlbum struct {
|
type MockAlbumRepo struct {
|
||||||
model.AlbumRepository
|
model.AlbumRepository
|
||||||
data map[string]model.Album
|
data map[string]model.Album
|
||||||
all model.Albums
|
all model.Albums
|
||||||
|
@ -18,11 +18,11 @@ type MockAlbum struct {
|
||||||
Options model.QueryOptions
|
Options model.QueryOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) SetError(err bool) {
|
func (m *MockAlbumRepo) SetError(err bool) {
|
||||||
m.err = err
|
m.err = err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) SetData(albums model.Albums) {
|
func (m *MockAlbumRepo) SetData(albums model.Albums) {
|
||||||
m.data = make(map[string]model.Album)
|
m.data = make(map[string]model.Album)
|
||||||
m.all = albums
|
m.all = albums
|
||||||
for _, a := range m.all {
|
for _, a := range m.all {
|
||||||
|
@ -30,7 +30,7 @@ func (m *MockAlbum) SetData(albums model.Albums) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) Exists(id string) (bool, error) {
|
func (m *MockAlbumRepo) Exists(id string) (bool, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return false, errors.New("Error!")
|
return false, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func (m *MockAlbum) Exists(id string) (bool, error) {
|
||||||
return found, nil
|
return found, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) Get(id string) (*model.Album, error) {
|
func (m *MockAlbumRepo) Get(id string) (*model.Album, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func (m *MockAlbum) Get(id string) (*model.Album, error) {
|
||||||
return nil, model.ErrNotFound
|
return nil, model.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) GetAll(qo ...model.QueryOptions) (model.Albums, error) {
|
func (m *MockAlbumRepo) GetAll(qo ...model.QueryOptions) (model.Albums, error) {
|
||||||
if len(qo) > 0 {
|
if len(qo) > 0 {
|
||||||
m.Options = qo[0]
|
m.Options = qo[0]
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func (m *MockAlbum) GetAll(qo ...model.QueryOptions) (model.Albums, error) {
|
||||||
return m.all, nil
|
return m.all, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockAlbum) FindByArtist(artistId string) (model.Albums, error) {
|
func (m *MockAlbumRepo) FindByArtist(artistId string) (model.Albums, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -74,4 +74,4 @@ func (m *MockAlbum) FindByArtist(artistId string) (model.Albums, error) {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ model.AlbumRepository = (*MockAlbum)(nil)
|
var _ model.AlbumRepository = (*MockAlbumRepo)(nil)
|
||||||
|
|
|
@ -6,28 +6,28 @@ import (
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateMockArtistRepo() *MockArtist {
|
func CreateMockArtistRepo() *MockArtistRepo {
|
||||||
return &MockArtist{}
|
return &MockArtistRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockArtist struct {
|
type MockArtistRepo struct {
|
||||||
model.ArtistRepository
|
model.ArtistRepository
|
||||||
data map[string]model.Artist
|
data map[string]model.Artist
|
||||||
err bool
|
err bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockArtist) SetError(err bool) {
|
func (m *MockArtistRepo) SetError(err bool) {
|
||||||
m.err = err
|
m.err = err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockArtist) SetData(artists model.Artists) {
|
func (m *MockArtistRepo) SetData(artists model.Artists) {
|
||||||
m.data = make(map[string]model.Artist)
|
m.data = make(map[string]model.Artist)
|
||||||
for _, a := range artists {
|
for _, a := range artists {
|
||||||
m.data[a.ID] = a
|
m.data[a.ID] = a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockArtist) Exists(id string) (bool, error) {
|
func (m *MockArtistRepo) Exists(id string) (bool, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return false, errors.New("Error!")
|
return false, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func (m *MockArtist) Exists(id string) (bool, error) {
|
||||||
return found, nil
|
return found, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockArtist) Get(id string) (*model.Artist, error) {
|
func (m *MockArtistRepo) Get(id string) (*model.Artist, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -45,4 +45,4 @@ func (m *MockArtist) Get(id string) (*model.Artist, error) {
|
||||||
return nil, model.ErrNotFound
|
return nil, model.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ model.ArtistRepository = (*MockArtist)(nil)
|
var _ model.ArtistRepository = (*MockArtistRepo)(nil)
|
||||||
|
|
|
@ -6,28 +6,28 @@ import (
|
||||||
"github.com/navidrome/navidrome/model"
|
"github.com/navidrome/navidrome/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateMockMediaFileRepo() *MockMediaFile {
|
func CreateMockMediaFileRepo() *MockMediaFileRepo {
|
||||||
return &MockMediaFile{}
|
return &MockMediaFileRepo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockMediaFile struct {
|
type MockMediaFileRepo struct {
|
||||||
model.MediaFileRepository
|
model.MediaFileRepository
|
||||||
data map[string]model.MediaFile
|
data map[string]model.MediaFile
|
||||||
err bool
|
err bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMediaFile) SetError(err bool) {
|
func (m *MockMediaFileRepo) SetError(err bool) {
|
||||||
m.err = err
|
m.err = err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMediaFile) SetData(mfs model.MediaFiles) {
|
func (m *MockMediaFileRepo) SetData(mfs model.MediaFiles) {
|
||||||
m.data = make(map[string]model.MediaFile)
|
m.data = make(map[string]model.MediaFile)
|
||||||
for _, mf := range mfs {
|
for _, mf := range mfs {
|
||||||
m.data[mf.ID] = mf
|
m.data[mf.ID] = mf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMediaFile) Exists(id string) (bool, error) {
|
func (m *MockMediaFileRepo) Exists(id string) (bool, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return false, errors.New("Error!")
|
return false, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func (m *MockMediaFile) Exists(id string) (bool, error) {
|
||||||
return found, nil
|
return found, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMediaFile) Get(id string) (*model.MediaFile, error) {
|
func (m *MockMediaFileRepo) Get(id string) (*model.MediaFile, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func (m *MockMediaFile) Get(id string) (*model.MediaFile, error) {
|
||||||
return nil, model.ErrNotFound
|
return nil, model.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockMediaFile) FindByAlbum(artistId string) (model.MediaFiles, error) {
|
func (m *MockMediaFileRepo) FindByAlbum(artistId string) (model.MediaFiles, error) {
|
||||||
if m.err {
|
if m.err {
|
||||||
return nil, errors.New("Error!")
|
return nil, errors.New("Error!")
|
||||||
}
|
}
|
||||||
|
@ -61,4 +61,4 @@ func (m *MockMediaFile) FindByAlbum(artistId string) (model.MediaFiles, error) {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ model.MediaFileRepository = (*MockMediaFile)(nil)
|
var _ model.MediaFileRepository = (*MockMediaFileRepo)(nil)
|
||||||
|
|
|
@ -60,13 +60,16 @@ func (db *MockDataStore) PlayQueue(context.Context) model.PlayQueueRepository {
|
||||||
|
|
||||||
func (db *MockDataStore) Property(context.Context) model.PropertyRepository {
|
func (db *MockDataStore) Property(context.Context) model.PropertyRepository {
|
||||||
if db.MockedProperty == nil {
|
if db.MockedProperty == nil {
|
||||||
db.MockedProperty = &mockedPropertyRepo{}
|
db.MockedProperty = &MockedPropertyRepo{}
|
||||||
}
|
}
|
||||||
return db.MockedProperty
|
return db.MockedProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *MockDataStore) Share(context.Context) model.ShareRepository {
|
func (db *MockDataStore) Share(context.Context) model.ShareRepository {
|
||||||
return struct{ model.ShareRepository }{}
|
if db.MockedShare == nil {
|
||||||
|
db.MockedShare = &MockShareRepo{}
|
||||||
|
}
|
||||||
|
return db.MockedShare
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *MockDataStore) User(context.Context) model.UserRepository {
|
func (db *MockDataStore) User(context.Context) model.UserRepository {
|
||||||
|
|
|
@ -2,19 +2,19 @@ package tests
|
||||||
|
|
||||||
import "github.com/navidrome/navidrome/model"
|
import "github.com/navidrome/navidrome/model"
|
||||||
|
|
||||||
type mockedPropertyRepo struct {
|
type MockedPropertyRepo struct {
|
||||||
model.UserRepository
|
model.UserRepository
|
||||||
data map[string]string
|
data map[string]string
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mockedPropertyRepo) init() {
|
func (p *MockedPropertyRepo) init() {
|
||||||
if p.data == nil {
|
if p.data == nil {
|
||||||
p.data = make(map[string]string)
|
p.data = make(map[string]string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mockedPropertyRepo) Put(id string, value string) error {
|
func (p *MockedPropertyRepo) Put(id string, value string) error {
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
return p.err
|
return p.err
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func (p *mockedPropertyRepo) Put(id string, value string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mockedPropertyRepo) Get(id string) (string, error) {
|
func (p *MockedPropertyRepo) Get(id string) (string, error) {
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
return "", p.err
|
return "", p.err
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func (p *mockedPropertyRepo) Get(id string) (string, error) {
|
||||||
return "", model.ErrNotFound
|
return "", model.ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *mockedPropertyRepo) DefaultGet(id string, defaultValue string) (string, error) {
|
func (p *MockedPropertyRepo) DefaultGet(id string, defaultValue string) (string, error) {
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
return "", p.err
|
return "", p.err
|
||||||
}
|
}
|
||||||
|
|
27
tests/mock_share_repo.go
Normal file
27
tests/mock_share_repo.go
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
package tests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/deluan/rest"
|
||||||
|
"github.com/navidrome/navidrome/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MockShareRepo struct {
|
||||||
|
model.ShareRepository
|
||||||
|
rest.Repository
|
||||||
|
rest.Persistable
|
||||||
|
|
||||||
|
Entity interface{}
|
||||||
|
Cols []string
|
||||||
|
Err error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockShareRepo) Save(entity interface{}) (string, error) {
|
||||||
|
m.Entity = entity
|
||||||
|
return "id", m.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockShareRepo) Update(entity interface{}, cols ...string) error {
|
||||||
|
m.Entity = entity
|
||||||
|
m.Cols = cols
|
||||||
|
return m.Err
|
||||||
|
}
|
|
@ -2,15 +2,15 @@ package tests
|
||||||
|
|
||||||
import "github.com/navidrome/navidrome/model"
|
import "github.com/navidrome/navidrome/model"
|
||||||
|
|
||||||
type MockTranscodingRepository struct {
|
type MockTranscodingRepo struct {
|
||||||
model.TranscodingRepository
|
model.TranscodingRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockTranscodingRepository) Get(id string) (*model.Transcoding, error) {
|
func (m *MockTranscodingRepo) Get(id string) (*model.Transcoding, error) {
|
||||||
return &model.Transcoding{ID: id, TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
return &model.Transcoding{ID: id, TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockTranscodingRepository) FindByFormat(format string) (*model.Transcoding, error) {
|
func (m *MockTranscodingRepo) FindByFormat(format string) (*model.Transcoding, error) {
|
||||||
switch format {
|
switch format {
|
||||||
case "mp3":
|
case "mp3":
|
||||||
return &model.Transcoding{ID: "mp31", TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
return &model.Transcoding{ID: "mp31", TargetFormat: "mp3", DefaultBitRate: 160}, nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue