mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
initial Go port of streamrip
This commit is contained in:
107
internal/urlparse/parse_test.go
Normal file
107
internal/urlparse/parse_test.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package urlparse
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDeezerDynamicURL(t *testing.T) {
|
||||
url := "https://dzr.page.link/SnV6hCyHihkmCCwUA"
|
||||
result := Parse(url)
|
||||
if result == nil {
|
||||
t.Fatalf("expected parsed url")
|
||||
}
|
||||
if result.Source != "deezer" {
|
||||
t.Fatalf("source = %q, want deezer", result.Source)
|
||||
}
|
||||
if result.Kind != KindDeezerDynamic {
|
||||
t.Fatalf("kind = %q, want %q", result.Kind, KindDeezerDynamic)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQobuzAlbumURL(t *testing.T) {
|
||||
url := "https://www.qobuz.com/fr-fr/album/bizarre-ride-ii-the-pharcyde-the-pharcyde/0066991040005"
|
||||
result := Parse(url)
|
||||
if result == nil {
|
||||
t.Fatalf("expected parsed url")
|
||||
}
|
||||
if result.Source != "qobuz" || result.MediaType != "album" || result.ID != "0066991040005" {
|
||||
t.Fatalf("unexpected parse result: %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTidalTrackURL(t *testing.T) {
|
||||
url := "https://tidal.com/browse/track/3083287"
|
||||
result := Parse(url)
|
||||
if result == nil {
|
||||
t.Fatalf("expected parsed url")
|
||||
}
|
||||
if result.Source != "tidal" || result.MediaType != "track" || result.ID != "3083287" {
|
||||
t.Fatalf("unexpected parse result: %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeezerTrackURL(t *testing.T) {
|
||||
url := "https://www.deezer.com/track/4195713"
|
||||
result := Parse(url)
|
||||
if result == nil {
|
||||
t.Fatalf("expected parsed url")
|
||||
}
|
||||
if result.Source != "deezer" || result.MediaType != "track" || result.ID != "4195713" {
|
||||
t.Fatalf("unexpected parse result: %+v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidURL(t *testing.T) {
|
||||
inputs := []string{
|
||||
"https://example.com",
|
||||
"not a url",
|
||||
"https://spotify.com/track/123456",
|
||||
"https://tidal.com/invalid/3083287",
|
||||
}
|
||||
for _, input := range inputs {
|
||||
if result := Parse(input); result != nil {
|
||||
t.Fatalf("expected nil for %q, got %+v", input, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlternateURLFormats(t *testing.T) {
|
||||
inputs := []string{
|
||||
"https://open.tidal.com/track/3083287",
|
||||
"https://play.qobuz.com/album/0066991040005",
|
||||
"https://listen.tidal.com/track/3083287",
|
||||
}
|
||||
for _, input := range inputs {
|
||||
if result := Parse(input); result == nil {
|
||||
t.Fatalf("expected parse for %q", input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestURLWithLanguageCode(t *testing.T) {
|
||||
inputs := []string{
|
||||
"https://www.qobuz.com/us-en/album/name/id123456",
|
||||
"https://www.qobuz.com/gb-en/album/name/id123456",
|
||||
"https://www.deezer.com/en/track/4195713",
|
||||
"https://www.deezer.com/fr/track/4195713",
|
||||
}
|
||||
for _, input := range inputs {
|
||||
if result := Parse(input); result == nil {
|
||||
t.Fatalf("expected parse for %q", input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSoundcloudURL(t *testing.T) {
|
||||
inputs := []string{
|
||||
"https://soundcloud.com/artist-name/track-name",
|
||||
"https://soundcloud.com/artist-name/sets/playlist-name",
|
||||
}
|
||||
for _, input := range inputs {
|
||||
result := Parse(input)
|
||||
if result == nil {
|
||||
t.Fatalf("expected parse for %q", input)
|
||||
}
|
||||
if result.Source != "soundcloud" || result.Kind != KindSoundcloud {
|
||||
t.Fatalf("unexpected parse result: %+v", result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user