|
@@ -5,6 +5,7 @@ package model
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"os"
|
|
"os"
|
|
|
|
|
+ "slices"
|
|
|
"testing"
|
|
"testing"
|
|
|
|
|
|
|
|
"miniflux.app/v2/internal/config"
|
|
"miniflux.app/v2/internal/config"
|
|
@@ -204,6 +205,90 @@ func TestEnclosureList_FindMediaPlayerEnclosure(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func TestEnclosureList_MediaPlayerSources(t *testing.T) {
|
|
|
|
|
+ testCases := []struct {
|
|
|
|
|
+ name string
|
|
|
|
|
+ enclosures EnclosureList
|
|
|
|
|
+ expectedURLs []string
|
|
|
|
|
+ }{
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Returns nil for nil list",
|
|
|
|
|
+ enclosures: nil,
|
|
|
|
|
+ expectedURLs: nil,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Returns nil for no media enclosures",
|
|
|
|
|
+ enclosures: EnclosureList{
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/image.jpg", MimeType: "image/jpeg"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/doc.pdf", MimeType: "application/pdf"},
|
|
|
|
|
+ },
|
|
|
|
|
+ expectedURLs: nil,
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Returns single audio enclosure",
|
|
|
|
|
+ enclosures: EnclosureList{
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/audio.mp3", MimeType: "audio/mpeg"},
|
|
|
|
|
+ },
|
|
|
|
|
+ expectedURLs: []string{"http://example.com/audio.mp3"},
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Returns video enclosures only, in feed order",
|
|
|
|
|
+ enclosures: EnclosureList{
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/thumbnail.jpg", MimeType: "image/*"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/generate", MimeType: "video/mp4"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/audio-only.mp4", MimeType: "audio/mp4"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/1080.mp4", MimeType: "video/mp4"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/720.webm", MimeType: "VIDEO/WEBM"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/video.torrent", MimeType: "application/x-bittorrent"},
|
|
|
|
|
+ },
|
|
|
|
|
+ expectedURLs: []string{"http://example.com/generate", "http://example.com/1080.mp4", "http://example.com/720.webm"},
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Returns audio enclosures only when the first media is audio",
|
|
|
|
|
+ enclosures: EnclosureList{
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/audio.mp3", MimeType: "audio/mpeg"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/video.mp4", MimeType: "video/mp4"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/audio.ogg", MimeType: "audio/ogg"},
|
|
|
|
|
+ },
|
|
|
|
|
+ expectedURLs: []string{"http://example.com/audio.mp3", "http://example.com/audio.ogg"},
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: "Skips enclosures with empty URL",
|
|
|
|
|
+ enclosures: EnclosureList{
|
|
|
|
|
+ &Enclosure{URL: "", MimeType: "video/mp4"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/video.mp4", MimeType: "video/mp4"},
|
|
|
|
|
+ &Enclosure{URL: "", MimeType: "video/mp4"},
|
|
|
|
|
+ &Enclosure{URL: "http://example.com/video.webm", MimeType: "video/webm"},
|
|
|
|
|
+ },
|
|
|
|
|
+ expectedURLs: []string{"http://example.com/video.mp4", "http://example.com/video.webm"},
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, testCase := range testCases {
|
|
|
|
|
+ t.Run(testCase.name, func(t *testing.T) {
|
|
|
|
|
+ sources := testCase.enclosures.MediaPlayerSources()
|
|
|
|
|
+ if testCase.expectedURLs == nil {
|
|
|
|
|
+ if sources != nil {
|
|
|
|
|
+ t.Fatalf("MediaPlayerSources() = %d sources, want nil", len(sources))
|
|
|
|
|
+ }
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if sources[0] != testCase.enclosures.FindMediaPlayerEnclosure() {
|
|
|
|
|
+ t.Errorf("MediaPlayerSources()[0] is not the media player enclosure")
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ sourceURLs := make([]string, 0, len(sources))
|
|
|
|
|
+ for _, source := range sources {
|
|
|
|
|
+ sourceURLs = append(sourceURLs, source.URL)
|
|
|
|
|
+ }
|
|
|
|
|
+ if !slices.Equal(sourceURLs, testCase.expectedURLs) {
|
|
|
|
|
+ t.Errorf("MediaPlayerSources() URLs = %v, want %v", sourceURLs, testCase.expectedURLs)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestEnclosureList_ContainsAudioOrVideo(t *testing.T) {
|
|
func TestEnclosureList_ContainsAudioOrVideo(t *testing.T) {
|
|
|
testCases := []struct {
|
|
testCases := []struct {
|
|
|
name string
|
|
name string
|