Skip to content

🎧 Your Personal Streaming Service

Make mocks strongly typed

Deluan313a088f865b
diff --git a/core/artwork_test.go b/core/artwork_test.go
index a8a0d41d9..289bca847 100644
--- a/core/artwork_test.go
+++ b/core/artwork_test.go
@@ -22,8 +22,15 @@ var _ = Describe("Artwork", func() {
BeforeEach(func() {
ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}
- ds.Album(ctx).(*persistence.MockAlbum).SetData(`[{"id": "222", "coverArtId": "123", "coverArtPath":"tests/fixtures/test.mp3"}, {"id": "333", "coverArtId": ""}, {"id": "444", "coverArtId": "444", "coverArtPath": "tests/fixtures/cover.jpg"}]`)
- ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(`[{"id": "123", "albumId": "222", "path": "tests/fixtures/test.mp3", "hasCoverArt": true, "updatedAt":"2020-04-02T21:29:31.6377Z"},{"id": "456", "albumId": "222", "path": "tests/fixtures/test.ogg", "hasCoverArt": false, "updatedAt":"2020-04-02T21:29:31.6377Z"}]`)
+ ds.Album(ctx).(*persistence.MockAlbum).SetData(model.Albums{
+ {ID: "222", CoverArtId: "123", CoverArtPath: "tests/fixtures/test.mp3"},
+ {ID: "333", CoverArtId: ""},
+ {ID: "444", CoverArtId: "444", CoverArtPath: "tests/fixtures/cover.jpg"},
+ })
+ ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(model.MediaFiles{
+ {ID: "123", AlbumID: "222", Path: "tests/fixtures/test.mp3", HasCoverArt: true},
+ {ID: "456", AlbumID: "222", Path: "tests/fixtures/test.ogg", HasCoverArt: false},
+ })
})
Context("Cache is configured", func() {
diff --git a/core/media_streamer_test.go b/core/media_streamer_test.go
index ddb1b0aed..4a5ed6e82 100644
--- a/core/media_streamer_test.go
+++ b/core/media_streamer_test.go
@@ -26,7 +26,9 @@ var _ = Describe("MediaStreamer", func() {
conf.Server.DataFolder, _ = ioutil.TempDir("", "file_caches")
conf.Server.TranscodingCacheSize = "100MB"
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}]`)
+ ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(model.MediaFiles{
+ {ID: "123", Path: "tests/fixtures/test.mp3", Suffix: "mp3", BitRate: 128, Duration: 257.0},
+ })
testCache := NewTranscodingCache()
Eventually(func() bool { return testCache.Ready() }).Should(BeTrue())
streamer = NewMediaStreamer(ds, ffmpeg, testCache)
diff --git a/persistence/mock_album_repo.go b/persistence/mock_album_repo.go
index c4c82a94f..437b81f36 100644
--- a/persistence/mock_album_repo.go
+++ b/persistence/mock_album_repo.go
@@ -1,9 +1,7 @@
package persistence
import (
- "encoding/json"
"errors"
- "fmt"
"github.com/deluan/navidrome/model"
)
@@ -24,13 +22,9 @@ func (m *MockAlbum) SetError(err bool) {
m.err = err
}
-func (m *MockAlbum) SetData(j string) {
+func (m *MockAlbum) SetData(albums model.Albums) {
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)
- }
+ m.all = albums
for _, a := range m.all {
m.data[a.ID] = a
}
diff --git a/persistence/mock_artist_repo.go b/persistence/mock_artist_repo.go
index 2a159d617..0fadf520f 100644
--- a/persistence/mock_artist_repo.go
+++ b/persistence/mock_artist_repo.go
@@ -1,9 +1,7 @@
package persistence
import (
- "encoding/json"
"errors"
- "fmt"
"github.com/deluan/navidrome/model"
)
@@ -22,14 +20,9 @@ func (m *MockArtist) SetError(err bool) {
m.err = err
}
-func (m *MockArtist) SetData(j string) {
+func (m *MockArtist) SetData(artists model.Artists) {
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 {
+ for _, a := range artists {
m.data[a.ID] = a
}
}
diff --git a/persistence/mock_mediafile_repo.go b/persistence/mock_mediafile_repo.go
index 7897f5455..410ab36cb 100644
--- a/persistence/mock_mediafile_repo.go
+++ b/persistence/mock_mediafile_repo.go
@@ -1,9 +1,7 @@
package persistence
import (
- "encoding/json"
"errors"
- "fmt"
"github.com/deluan/navidrome/model"
)
@@ -22,15 +20,10 @@ func (m *MockMediaFile) SetError(err bool) {
m.err = err
}
-func (m *MockMediaFile) SetData(j string) {
+func (m *MockMediaFile) SetData(mfs model.MediaFiles) {
m.data = make(map[string]model.MediaFile)
- var l = model.MediaFiles{}
- err := json.Unmarshal([]byte(j), &l)
- if err != nil {
- fmt.Println("ERROR: ", err)
- }
- for _, a := range l {
- m.data[a.ID] = a
+ for _, mf := range mfs {
+ m.data[mf.ID] = mf
}
}
diff --git a/server/subsonic/album_lists_test.go b/server/subsonic/album_lists_test.go
index 8e4c6c8d7..d1ed60474 100644
--- a/server/subsonic/album_lists_test.go
+++ b/server/subsonic/album_lists_test.go
@@ -28,7 +28,9 @@ var _ = Describe("AlbumListController", func() {
Describe("GetAlbumList", func() {
It("should return list of the type specified", func() {
r := newGetRequest("type=newest", "offset=10", "size=20")
- mockRepo.SetData(`[{"id": "1"},{"id": "2"}]`)
+ mockRepo.SetData(model.Albums{
+ {ID: "1"}, {ID: "2"},
+ })
resp, err := controller.GetAlbumList(w, r)
Expect(err).To(BeNil())
@@ -58,7 +60,9 @@ var _ = Describe("AlbumListController", func() {
Describe("GetAlbumList2", func() {
It("should return list of the type specified", func() {
r := newGetRequest("type=newest", "offset=10", "size=20")
- mockRepo.SetData(`[{"id": "1"},{"id": "2"}]`)
+ mockRepo.SetData(model.Albums{
+ {ID: "1"}, {ID: "2"},
+ })
resp, err := controller.GetAlbumList2(w, r)
Expect(err).To(BeNil())