🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Add tests for external album cover processing
Alex Palaistrasbb9a7fadc054
diff --git a/engine/cover_test.go b/engine/cover_test.goindex 329bc6145..5a4944454 100644--- a/engine/cover_test.go+++ b/engine/cover_test.go@@ -19,7 +19,7 @@ var _ = Describe("Cover", func() {BeforeEach(func() {ds = &persistence.MockDataStore{MockedTranscoding: &mockTranscodingRepository{}}- ds.Album(ctx).(*persistence.MockAlbum).SetData(`[{"id": "222", "coverArtId": "123"}, {"id": "333", "coverArtId": ""}]`)+ ds.Album(ctx).(*persistence.MockAlbum).SetData(`[{"id": "222", "coverArtId": "123"}, {"id": "333", "coverArtId": ""}, {"id": "444", "coverArtId": "444", "coverArtPath": "tests/fixtures/cover.jpg"}]`)ds.MediaFile(ctx).(*persistence.MockMediaFile).SetData(`[{"id": "123", "path": "tests/fixtures/test.mp3", "hasCoverArt": true, "updatedAt":"2020-04-02T21:29:31.6377Z"}]`)})@@ -58,11 +58,21 @@ var _ = Describe("Cover", func() {Expect(format).To(Equal("png"))})- It("returns the default cover if album is not found", func() {+ It("returns the external cover for the album", func() {buf := new(bytes.Buffer)Expect(cover.Get(ctx, "444", 0, buf)).To(BeNil())+ _, format, err := image.Decode(bytes.NewReader(buf.Bytes()))+ Expect(err).To(BeNil())+ Expect(format).To(Equal("jpeg"))+ })++ It("returns the default cover if album is not found", func() {+ buf := new(bytes.Buffer)++ Expect(cover.Get(ctx, "0101", 0, buf)).To(BeNil())+_, format, err := image.Decode(bytes.NewReader(buf.Bytes()))Expect(err).To(BeNil())Expect(format).To(Equal("png"))diff --git a/persistence/album_repository_test.go b/persistence/album_repository_test.goindex a5f729089..d0d291745 100644--- a/persistence/album_repository_test.go+++ b/persistence/album_repository_test.go@@ -2,8 +2,12 @@ package persistenceimport ("context"+ "io/ioutil"+ "os"+ "path/filepath""github.com/astaxie/beego/orm"+ "github.com/deluan/navidrome/conf""github.com/deluan/navidrome/log""github.com/deluan/navidrome/model""github.com/deluan/navidrome/model/request"@@ -86,4 +90,51 @@ var _ = Describe("AlbumRepository", func() {Expect(getMinYear("2000 0 1800")).To(Equal(1800))})})++ Describe("getCoverFromPath", func() {+ testFolder, _ := ioutil.TempDir("", "album_persistence_tests")+ if err := os.MkdirAll(testFolder, 0777); err != nil {+ panic(err)+ }+ if _, err := os.Create(filepath.Join(testFolder, "Cover.jpeg")); err != nil {+ panic(err)+ }+ if _, err := os.Create(filepath.Join(testFolder, "FRONT.PNG")); err != nil {+ panic(err)+ }++ testPath := filepath.Join(testFolder, "somefile.test")+ It("returns audio file for embedded cover", func() {+ conf.Server.CoverArtPriority = "embedded, cover.*, front.*"+ Expect(getCoverFromPath(testPath, true)).To(Equal(""))+ })++ It("returns external file when no embedded cover exists", func() {+ conf.Server.CoverArtPriority = "embedded, cover.*, front.*"+ Expect(getCoverFromPath(testPath, false)).To(Equal(filepath.Join(testFolder, "Cover.jpeg")))+ })++ It("returns embedded cover even if not first choice", func() {+ conf.Server.CoverArtPriority = "something.png, embedded, cover.*, front.*"+ Expect(getCoverFromPath(testPath, true)).To(Equal(""))+ })++ It("returns first correct match case-insensitively", func() {+ conf.Server.CoverArtPriority = "embedded, cover.jpg, front.svg, front.png"+ Expect(getCoverFromPath(testPath, false)).To(Equal(filepath.Join(testFolder, "FRONT.PNG")))+ })++ It("returns match for embedded pattern", func() {+ conf.Server.CoverArtPriority = "embedded, cover.jp?g, front.png"+ Expect(getCoverFromPath(testPath, false)).To(Equal(filepath.Join(testFolder, "Cover.jpeg")))+ })++ It("returns empty string if no match was found", func() {+ conf.Server.CoverArtPriority = "embedded, cover.jpg, front.apng"+ Expect(getCoverFromPath(testPath, false)).To(Equal(""))+ })++ // Reset configuration to default.+ conf.Server.CoverArtPriority = "embedded, cover.*, front.*"+ })})diff --git a/tests/fixtures/cover.jpg b/tests/fixtures/cover.jpgnew file mode 100644index 000000000..6995905d7Binary files /dev/null and b/tests/fixtures/cover.jpg differ