diff options
Diffstat (limited to 'internal/reader/rss/parser_test.go')
-rw-r--r-- | internal/reader/rss/parser_test.go | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/internal/reader/rss/parser_test.go b/internal/reader/rss/parser_test.go index e4ff09ed..41b36e8e 100644 --- a/internal/reader/rss/parser_test.go +++ b/internal/reader/rss/parser_test.go @@ -846,6 +846,59 @@ func TestParseEntryWithEnclosures(t *testing.T) { } } +func TestParseEntryWithIncorrectEnclosureLength(t *testing.T) { + data := `<?xml version="1.0" encoding="utf-8"?> + <rss version="2.0"> + <channel> + <title>My Podcast Feed</title> + <link>http://example.org</link> + <author>some.email@example.org</author> + <item> + <title>Podcasting with RSS</title> + <link>http://www.example.org/entries/1</link> + <description>An overview of RSS podcasting</description> + <pubDate>Fri, 15 Jul 2005 00:00:00 -0500</pubDate> + <guid isPermaLink="true">http://www.example.org/entries/1</guid> + <enclosure url="http://www.example.org/myaudiofile.mp3" length="invalid" type="audio/mpeg" /> + <enclosure url="http://www.example.org/myaudiofile.wav" length=" " type="audio" /> + </item> + </channel> + </rss>` + + feed, err := Parse("https://example.org/", bytes.NewReader([]byte(data))) + if err != nil { + t.Fatal(err) + } + + if len(feed.Entries) != 1 { + t.Errorf("Incorrect number of entries, got: %d", len(feed.Entries)) + } + + if feed.Entries[0].URL != "http://www.example.org/entries/1" { + t.Errorf("Incorrect entry URL, got: %s", feed.Entries[0].URL) + } + + if len(feed.Entries[0].Enclosures) != 2 { + t.Errorf("Incorrect number of enclosures, got: %d", len(feed.Entries[0].Enclosures)) + } + + if feed.Entries[0].Enclosures[0].URL != "http://www.example.org/myaudiofile.mp3" { + t.Errorf("Incorrect enclosure URL, got: %s", feed.Entries[0].Enclosures[0].URL) + } + + if feed.Entries[0].Enclosures[0].MimeType != "audio/mpeg" { + t.Errorf("Incorrect enclosure type, got: %s", feed.Entries[0].Enclosures[0].MimeType) + } + + if feed.Entries[0].Enclosures[0].Size != 0 { + t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size) + } + + if feed.Entries[0].Enclosures[1].Size != 0 { + t.Errorf("Incorrect enclosure length, got: %d", feed.Entries[0].Enclosures[0].Size) + } +} + func TestParseEntryWithEmptyEnclosureURL(t *testing.T) { data := `<?xml version="1.0" encoding="utf-8"?> <rss version="2.0"> @@ -1306,6 +1359,60 @@ func TestParseEntryWithMediaPeerLink(t *testing.T) { } } +func TestParseItunesDuration(t *testing.T) { + data := `<?xml version="1.0" encoding="UTF-8"?> + <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> + <channel> + <title>Podcast Example</title> + <link>http://www.example.com/index.html</link> + <item> + <title>Podcast Episode</title> + <guid>http://example.com/episode.m4a</guid> + <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate> + <itunes:duration>1:23:45</itunes:duration> + </item> + </channel> + </rss>` + + feed, err := Parse("https://example.org/", bytes.NewReader([]byte(data))) + if err != nil { + t.Fatal(err) + } + + expected := 83 + result := feed.Entries[0].ReadingTime + if expected != result { + t.Errorf(`Unexpected podcast duration, got %d instead of %d`, result, expected) + } +} + +func TestParseIncorrectItunesDuration(t *testing.T) { + data := `<?xml version="1.0" encoding="UTF-8"?> + <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> + <channel> + <title>Podcast Example</title> + <link>http://www.example.com/index.html</link> + <item> + <title>Podcast Episode</title> + <guid>http://example.com/episode.m4a</guid> + <pubDate>Tue, 08 Mar 2016 12:00:00 GMT</pubDate> + <itunes:duration>invalid</itunes:duration> + </item> + </channel> + </rss>` + + feed, err := Parse("https://example.org/", bytes.NewReader([]byte(data))) + if err != nil { + t.Fatal(err) + } + + expected := 0 + result := feed.Entries[0].ReadingTime + if expected != result { + t.Errorf(`Unexpected podcast duration, got %d instead of %d`, result, expected) + } +} + func TestEntryDescriptionFromItunesSummary(t *testing.T) { data := `<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"> |