mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-15 11:40:36 +03:00
Fix tests for Cover service
This commit is contained in:
parent
4fc88f23e9
commit
5265d0234f
@ -18,8 +18,8 @@ var _ = Describe("Cover", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
||||
ds.Album(ctx).(*persistence.MockAlbum).SetData(`[{"id": "222", "CoverArtId": "222"}, {"id": "333", "CoverArtId": ""}]`, 1)
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(`[{"id": "123", "path": "tests/fixtures/test.mp3", "hasCoverArt": true, "updatedAt":"2020-04-02T21:29:31.6377Z"}]`, 1)
|
||||
ds.Album(ctx).(*persistence.MockAlbum).SetData(`[{"id": "222", "coverArtId": "123"}, {"id": "333", "coverArtId": ""}]`)
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(`[{"id": "123", "path": "tests/fixtures/test.mp3", "hasCoverArt": true, "updatedAt":"2020-04-02T21:29:31.6377Z"}]`)
|
||||
cover = NewCover(ds, testCache)
|
||||
})
|
||||
|
||||
@ -30,7 +30,7 @@ var _ = Describe("Cover", func() {
|
||||
|
||||
_, format, err := image.Decode(bytes.NewReader(buf.Bytes()))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(format).To(Equal("png"))
|
||||
Expect(format).To(Equal("jpeg"))
|
||||
})
|
||||
|
||||
It("accepts albumIds with 'al-' prefix", func() {
|
||||
@ -38,8 +38,9 @@ var _ = Describe("Cover", func() {
|
||||
|
||||
Expect(cover.Get(ctx, "al-222", 0, buf)).To(BeNil())
|
||||
|
||||
_, _, err := image.Decode(bytes.NewReader(buf.Bytes()))
|
||||
_, format, err := image.Decode(bytes.NewReader(buf.Bytes()))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(format).To(Equal("jpeg"))
|
||||
})
|
||||
|
||||
It("returns the default cover if album does not have cover", func() {
|
||||
@ -79,10 +80,26 @@ var _ = Describe("Cover", func() {
|
||||
|
||||
Expect(cover.Get(ctx, "123", 200, buf)).To(BeNil())
|
||||
|
||||
img, _, err := image.Decode(bytes.NewReader(buf.Bytes()))
|
||||
img, format, err := image.Decode(bytes.NewReader(buf.Bytes()))
|
||||
Expect(err).To(BeNil())
|
||||
Expect(format).To(Equal("jpeg"))
|
||||
Expect(img.Bounds().Size().X).To(Equal(200))
|
||||
Expect(img.Bounds().Size().Y).To(Equal(200))
|
||||
})
|
||||
|
||||
Context("Errors", func() {
|
||||
It("returns err if gets error from album table", func() {
|
||||
ds.Album(ctx).(*persistence.MockAlbum).SetError(true)
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
Expect(cover.Get(ctx, "222", 0, buf)).To(MatchError("Error!"))
|
||||
})
|
||||
|
||||
It("returns err if gets error from media_file table", func() {
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetError(true)
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
Expect(cover.Get(ctx, "123", 0, buf)).To(MatchError("Error!"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -20,7 +20,7 @@ var _ = Describe("MediaStreamer", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(`[{"id": "123", "path": "tests/fixtures/test.mp3", "suffix": "mp3", "bitRate": 128, "duration": 257.0}]`, 1)
|
||||
ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(`[{"id": "123", "path": "tests/fixtures/test.mp3", "suffix": "mp3", "bitRate": 128, "duration": 257.0}]`)
|
||||
streamer = NewMediaStreamer(ds, ffmpeg, testCache)
|
||||
})
|
||||
|
||||
|
@ -14,7 +14,7 @@ func CreateMockAlbumRepo() *MockAlbum {
|
||||
|
||||
type MockAlbum struct {
|
||||
model.AlbumRepository
|
||||
data map[string]*model.Album
|
||||
data map[string]model.Album
|
||||
all model.Albums
|
||||
err bool
|
||||
Options model.QueryOptions
|
||||
@ -24,19 +24,22 @@ func (m *MockAlbum) SetError(err bool) {
|
||||
m.err = err
|
||||
}
|
||||
|
||||
func (m *MockAlbum) SetData(j string, size int) {
|
||||
m.data = make(map[string]*model.Album)
|
||||
m.all = make(model.Albums, size)
|
||||
func (m *MockAlbum) SetData(j string) {
|
||||
m.data = make(map[string]model.Album)
|
||||
m.all = model.Albums{}
|
||||
err := json.Unmarshal([]byte(j), &m.all)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ", err)
|
||||
}
|
||||
for _, a := range m.all {
|
||||
m.data[a.ID] = &a
|
||||
m.data[a.ID] = a
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockAlbum) Exists(id string) (bool, error) {
|
||||
if m.err {
|
||||
return false, errors.New("Error!")
|
||||
}
|
||||
_, found := m.data[id]
|
||||
return found, nil
|
||||
}
|
||||
@ -46,7 +49,7 @@ func (m *MockAlbum) Get(id string) (*model.Album, error) {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
return d, nil
|
||||
return &d, nil
|
||||
}
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
@ -69,7 +72,7 @@ func (m *MockAlbum) FindByArtist(artistId string) (model.Albums, error) {
|
||||
i := 0
|
||||
for _, a := range m.data {
|
||||
if a.AlbumArtistID == artistId {
|
||||
res[i] = *a
|
||||
res[i] = a
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ func CreateMockArtistRepo() *MockArtist {
|
||||
|
||||
type MockArtist struct {
|
||||
model.ArtistRepository
|
||||
data map[string]*model.Artist
|
||||
data map[string]model.Artist
|
||||
err bool
|
||||
}
|
||||
|
||||
@ -22,19 +22,22 @@ func (m *MockArtist) SetError(err bool) {
|
||||
m.err = err
|
||||
}
|
||||
|
||||
func (m *MockArtist) SetData(j string, size int) {
|
||||
m.data = make(map[string]*model.Artist)
|
||||
var l = make([]model.Artist, size)
|
||||
func (m *MockArtist) SetData(j string) {
|
||||
m.data = make(map[string]model.Artist)
|
||||
var l = model.Artists{}
|
||||
err := json.Unmarshal([]byte(j), &l)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ", err)
|
||||
}
|
||||
for _, a := range l {
|
||||
m.data[a.ID] = &a
|
||||
m.data[a.ID] = a
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MockArtist) Exists(id string) (bool, error) {
|
||||
if m.err {
|
||||
return false, errors.New("Error!")
|
||||
}
|
||||
_, found := m.data[id]
|
||||
return found, nil
|
||||
}
|
||||
@ -44,7 +47,7 @@ func (m *MockArtist) Get(id string) (*model.Artist, error) {
|
||||
return nil, errors.New("Error!")
|
||||
}
|
||||
if d, ok := m.data[id]; ok {
|
||||
return d, nil
|
||||
return &d, nil
|
||||
}
|
||||
return nil, model.ErrNotFound
|
||||
}
|
||||
|
@ -22,9 +22,9 @@ func (m *MockMediaFile) SetError(err bool) {
|
||||
m.err = err
|
||||
}
|
||||
|
||||
func (m *MockMediaFile) SetData(j string, size int) {
|
||||
func (m *MockMediaFile) SetData(j string) {
|
||||
m.data = make(map[string]model.MediaFile)
|
||||
var l = make(model.MediaFiles, size)
|
||||
var l = model.MediaFiles{}
|
||||
err := json.Unmarshal([]byte(j), &l)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR: ", err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user