mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
tighten lastfm parsing and locale url handling
This commit is contained in:
@@ -114,6 +114,9 @@ func TestIsValidLastFMPlaylistURL(t *testing.T) {
|
||||
if isValidLastFMPlaylistURL("https://example.com/user/x/playlists/123") {
|
||||
t.Fatalf("expected non-last.fm host to be invalid")
|
||||
}
|
||||
if isValidLastFMPlaylistURL("https://www.last.fm/user/x/library") {
|
||||
t.Fatalf("expected non-playlist last.fm url to be invalid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractLastFMPlaylistInfoAndPairs(t *testing.T) {
|
||||
@@ -144,6 +147,30 @@ func TestExtractLastFMPlaylistInfoAndPairs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractLastFMPlaylistInfoFlexibleClass(t *testing.T) {
|
||||
html := `<h1 id="x" class="foo playlisting-playlist-header-title bar">Road & Rain</h1>
|
||||
<div data-playlisting-entry-count="1"></div>`
|
||||
title, total, err := extractLastFMPlaylistInfo(html)
|
||||
if err != nil {
|
||||
t.Fatalf("extractLastFMPlaylistInfo() error = %v", err)
|
||||
}
|
||||
if title != "Road & Rain" || total != 1 {
|
||||
t.Fatalf("unexpected parsed values: title=%q total=%d", title, total)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractLastFMTitleArtistPairsSingleQuotes(t *testing.T) {
|
||||
html := `<a href='/music/a' title='Dreams'></a>
|
||||
<a href='/music/b' title='Fleetwood Mac'></a>`
|
||||
pairs := extractLastFMTitleArtistPairs(html)
|
||||
if len(pairs) != 1 {
|
||||
t.Fatalf("pairs len = %d, want 1", len(pairs))
|
||||
}
|
||||
if pairs[0].Title != "Dreams" || pairs[0].Artist != "Fleetwood Mac" {
|
||||
t.Fatalf("unexpected pair: %+v", pairs[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlobalArgsNoDBBeforeCommand(t *testing.T) {
|
||||
opts, err := parseGlobalArgs([]string{"-ndb", "url", "https://play.qobuz.com/album/0004228000522"})
|
||||
if err != nil {
|
||||
@@ -266,6 +293,26 @@ func TestWriteSearchResultsToFileCreatesParentDirectory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeSearchResultsDedupesByID(t *testing.T) {
|
||||
pages := []map[string]any{
|
||||
{"tracks": map[string]any{"items": []any{
|
||||
map[string]any{"id": "1", "title": "Dreams", "artist": map[string]any{"name": "Fleetwood Mac"}},
|
||||
map[string]any{"id": "1", "title": "Dreams", "artist": map[string]any{"name": "Fleetwood Mac"}},
|
||||
}}},
|
||||
{"tracks": map[string]any{"items": []any{
|
||||
map[string]any{"id": "2", "title": "Go Your Own Way", "artist": map[string]any{"name": "Fleetwood Mac"}},
|
||||
map[string]any{"id": "1", "title": "Dreams", "artist": map[string]any{"name": "Fleetwood Mac"}},
|
||||
}}},
|
||||
}
|
||||
results := normalizeSearchResults("qobuz", "track", pages)
|
||||
if len(results) != 2 {
|
||||
t.Fatalf("len(results)=%d want 2", len(results))
|
||||
}
|
||||
if results[0].ID != "1" || results[1].ID != "2" {
|
||||
t.Fatalf("unexpected IDs order: %+v", results)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorWithActionableHintForSSL(t *testing.T) {
|
||||
err := errors.New("x509: certificate signed by unknown authority")
|
||||
msg := errorWithActionableHint(err, globalOptions{})
|
||||
|
||||
Reference in New Issue
Block a user