|
|
@@ -11,7 +11,7 @@ import (
|
|
|
func TestFindYoutubeFeed(t *testing.T) {
|
|
|
type testResult struct {
|
|
|
websiteURL string
|
|
|
- feedURL string
|
|
|
+ feedURLs []string
|
|
|
discoveryError bool
|
|
|
}
|
|
|
|
|
|
@@ -19,57 +19,69 @@ func TestFindYoutubeFeed(t *testing.T) {
|
|
|
// Video URL
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
|
|
- feedURL: "",
|
|
|
+ feedURLs: []string{},
|
|
|
},
|
|
|
// Video URL with position argument
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=1",
|
|
|
- feedURL: "",
|
|
|
+ feedURLs: []string{},
|
|
|
},
|
|
|
// Video URL with position argument
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/watch?t=1&v=dQw4w9WgXcQ",
|
|
|
- feedURL: "",
|
|
|
+ feedURLs: []string{},
|
|
|
},
|
|
|
// Channel URL
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/channel/UC-Qj80avWItNRjkZ41rzHyw",
|
|
|
- feedURL: "https://www.youtube.com/feeds/videos.xml?channel_id=UC-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ feedURLs: []string{
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?channel_id=UC-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UULF-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UUSH-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UULV-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UULP-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UUPS-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UUPV-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UUMO-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UUMF-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UUMS-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ "https://www.youtube.com/feeds/videos.xml?playlist_id=UUMV-Qj80avWItNRjkZ41rzHyw",
|
|
|
+ },
|
|
|
},
|
|
|
// Channel URL with name
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/@ABCDEFG",
|
|
|
- feedURL: "",
|
|
|
+ feedURLs: []string{},
|
|
|
},
|
|
|
// Playlist URL
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/playlist?list=PLOOwEPgFWm_NHcQd9aCi5JXWASHO_n5uR",
|
|
|
- feedURL: "https://www.youtube.com/feeds/videos.xml?playlist_id=PLOOwEPgFWm_NHcQd9aCi5JXWASHO_n5uR",
|
|
|
+ feedURLs: []string{"https://www.youtube.com/feeds/videos.xml?playlist_id=PLOOwEPgFWm_NHcQd9aCi5JXWASHO_n5uR"},
|
|
|
},
|
|
|
// Playlist URL with video ID
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/watch?v=dQw4w9WgXcQ&list=PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM",
|
|
|
- feedURL: "https://www.youtube.com/feeds/videos.xml?playlist_id=PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM",
|
|
|
+ feedURLs: []string{"https://www.youtube.com/feeds/videos.xml?playlist_id=PLOOwEPgFWm_N42HlCLhqyJ0ZBWr5K1QDM"},
|
|
|
},
|
|
|
// Playlist URL with video ID and index argument
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/watch?v=6IutBmRJNLk&list=PLOOwEPgFWm_NHcQd9aCi5JXWASHO_n5uR&index=4",
|
|
|
- feedURL: "https://www.youtube.com/feeds/videos.xml?playlist_id=PLOOwEPgFWm_NHcQd9aCi5JXWASHO_n5uR",
|
|
|
+ feedURLs: []string{"https://www.youtube.com/feeds/videos.xml?playlist_id=PLOOwEPgFWm_NHcQd9aCi5JXWASHO_n5uR"},
|
|
|
},
|
|
|
// Empty playlist ID parameter
|
|
|
{
|
|
|
websiteURL: "https://www.youtube.com/playlist?list=",
|
|
|
- feedURL: "",
|
|
|
+ feedURLs: []string{},
|
|
|
},
|
|
|
// Non-Youtube URL
|
|
|
{
|
|
|
websiteURL: "https://www.example.com/channel/UC-Qj80avWItNRjkZ41rzHyw",
|
|
|
- feedURL: "",
|
|
|
+ feedURLs: []string{},
|
|
|
},
|
|
|
// Invalid URL
|
|
|
{
|
|
|
websiteURL: "https://example|org/",
|
|
|
- feedURL: "",
|
|
|
+ feedURLs: []string{},
|
|
|
discoveryError: true,
|
|
|
},
|
|
|
}
|
|
|
@@ -82,7 +94,7 @@ func TestFindYoutubeFeed(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if scenario.feedURL == "" {
|
|
|
+ if len(scenario.feedURLs) == 0 {
|
|
|
if len(subscriptions) > 0 {
|
|
|
t.Fatalf(`Parsing an invalid URL should not return any subscription: %q -> %v`, scenario.websiteURL, subscriptions)
|
|
|
}
|
|
|
@@ -91,12 +103,14 @@ func TestFindYoutubeFeed(t *testing.T) {
|
|
|
t.Fatalf(`Parsing a correctly formatted YouTube playlist or channel page should not return any error: %v`, localizedError)
|
|
|
}
|
|
|
|
|
|
- if len(subscriptions) != 1 {
|
|
|
- t.Fatalf(`Incorrect number of subscriptions returned`)
|
|
|
+ if len(subscriptions) != len(scenario.feedURLs) {
|
|
|
+ t.Fatalf(`Incorrect number of subscriptions returned, expected %d, got %d`, len(scenario.feedURLs), len(subscriptions))
|
|
|
}
|
|
|
|
|
|
- if subscriptions[0].URL != scenario.feedURL {
|
|
|
- t.Errorf(`Unexpected feed, got %s, instead of %s`, subscriptions[0].URL, scenario.feedURL)
|
|
|
+ for i := range scenario.feedURLs {
|
|
|
+ if subscriptions[i].URL != scenario.feedURLs[i] {
|
|
|
+ t.Errorf(`Unexpected feed, got %s, instead of %s`, subscriptions[i].URL, scenario.feedURLs[i])
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -397,3 +411,36 @@ func TestParseWebPageWithNoHref(t *testing.T) {
|
|
|
t.Fatal(`Incorrect number of subscriptions returned`)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestFindCanonicalURL(t *testing.T) {
|
|
|
+ htmlPage := `
|
|
|
+ <!doctype html>
|
|
|
+ <html>
|
|
|
+ <head>
|
|
|
+ <link rel="canonical" href="https://example.org/canonical-page">
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+ </body>
|
|
|
+ </html>`
|
|
|
+
|
|
|
+ canonicalURL := NewSubscriptionFinder(nil).findCanonicalURL("https://example.org/page", "text/html", strings.NewReader(htmlPage))
|
|
|
+ if canonicalURL != "https://example.org/canonical-page" {
|
|
|
+ t.Errorf(`Unexpected canonical URL, got %q, expected %q`, canonicalURL, "https://example.org/canonical-page")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestFindCanonicalURLNotFound(t *testing.T) {
|
|
|
+ htmlPage := `
|
|
|
+ <!doctype html>
|
|
|
+ <html>
|
|
|
+ <head>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+ </body>
|
|
|
+ </html>`
|
|
|
+
|
|
|
+ canonicalURL := NewSubscriptionFinder(nil).findCanonicalURL("https://example.org/page", "text/html", strings.NewReader(htmlPage))
|
|
|
+ if canonicalURL != "https://example.org/page" {
|
|
|
+ t.Errorf(`Expected effective URL when canonical not found, got %q`, canonicalURL)
|
|
|
+ }
|
|
|
+}
|