-
Notifications
You must be signed in to change notification settings - Fork 0
/
link_test.go
74 lines (70 loc) · 1.78 KB
/
link_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package streamnx
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestParseLink(t *testing.T) {
tests := []struct {
name string
url string
want *Link
expectedError error
}{
{
name: "Apple track",
url: "https://music.apple.com/us/album/song-name/1234567890?i=987654321",
want: &Link{
URL: "https://music.apple.com/us/album/song-name/1234567890?i=987654321",
Provider: Apple,
EntityID: "us-987654321",
EntityType: Track,
},
},
{
name: "Spotify album",
url: "https://open.spotify.com/album/7uv632EkfwYhXoqf8rhYrg",
want: &Link{
URL: "https://open.spotify.com/album/7uv632EkfwYhXoqf8rhYrg",
Provider: Spotify,
EntityID: "7uv632EkfwYhXoqf8rhYrg",
EntityType: Album,
},
},
{
name: "Yandex track",
url: "https://music.yandex.by/album/3192570/track/1197793",
want: &Link{
URL: "https://music.yandex.by/album/3192570/track/1197793",
Provider: Yandex,
EntityID: "1197793",
EntityType: Track,
},
},
{
name: "Youtube album",
url: "https://www.youtube.com/playlist?list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj",
want: &Link{
URL: "https://www.youtube.com/playlist?list=PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj",
Provider: Youtube,
EntityID: "PLMC9KNkIncKtPzgY-5rmhvj7fax8fdxoj",
EntityType: Album,
},
},
{
name: "Unknown provider",
url: "https://example.com/track/123456789",
expectedError: UnknownLinkError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ParseLink(tt.url)
if tt.expectedError != nil {
require.ErrorAs(t, err, &tt.expectedError)
} else {
require.NoError(t, err)
require.Equal(t, tt.want, got)
}
})
}
}