65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package apple
|
|
|
|
import "testing"
|
|
|
|
func TestParsePlaylistURL(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
url string
|
|
storefront string
|
|
playlist string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "us playlist",
|
|
url: "https://music.apple.com/us/playlist/indie-chill/pl.c4074df0f3114c7d9572859645229d75",
|
|
storefront: "us",
|
|
playlist: "pl.c4074df0f3114c7d9572859645229d75",
|
|
},
|
|
{
|
|
name: "gb playlist with query",
|
|
url: "https://music.apple.com/gb/playlist/name/pl.abc123?uo=4",
|
|
storefront: "gb",
|
|
playlist: "pl.abc123",
|
|
},
|
|
{
|
|
name: "beta host",
|
|
url: "https://beta.music.apple.com/de/playlist/x/pl.123",
|
|
storefront: "de",
|
|
playlist: "pl.123",
|
|
},
|
|
{
|
|
name: "wrong host",
|
|
url: "https://open.spotify.com/playlist/abc",
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "library playlist",
|
|
url: "https://music.apple.com/us/library/playlist/pl.123",
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "no playlist id",
|
|
url: "https://music.apple.com/us/album/name/123",
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
ref, err := ParsePlaylistURL(tc.url)
|
|
if tc.wantErr {
|
|
if err == nil {
|
|
t.Fatalf("expected error, got %+v", ref)
|
|
}
|
|
return
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if ref.Storefront != tc.storefront || ref.PlaylistID != tc.playlist {
|
|
t.Fatalf("got %+v, want storefront=%s playlist=%s", ref, tc.storefront, tc.playlist)
|
|
}
|
|
})
|
|
}
|
|
}
|