forked from kkdai/youtube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlist_test.go
72 lines (66 loc) · 1.41 KB
/
playlist_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
package youtube
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestYoutube_extractPlaylistID(t *testing.T) {
tests := []struct {
name string
url string
expectedID string
expectedError error
}{
{
"pass-1",
"https://www.youtube.com/watch?v=9UL390els7M&list=PLqAfPOrmacr963ATEroh67fbvjmTzTEx5",
"PLqAfPOrmacr963ATEroh67fbvjmTzTEx5",
nil,
},
{
"pass-2",
"PLqAfPOrmacr963ATEroh67fbvjmTzTEx5",
"PLqAfPOrmacr963ATEroh67fbvjmTzTEx5",
nil,
},
{
"pass-3",
"&list=PLqAfPOrmacr963ATEroh67fbvjmTzTEx5",
"PLqAfPOrmacr963ATEroh67fbvjmTzTEx5",
nil,
},
{
"pass-4 (extra params)",
"https://www.youtube.com/watch?v=9UL390els7M&list=PLqAfPOrmacr963ATEroh67fbvjmTzTEx5&foo=bar&baz=babar",
"PLqAfPOrmacr963ATEroh67fbvjmTzTEx5",
nil,
},
{
"pass-5",
"https://www.youtube.com/watch?v=-T4THwne8IE&list=RD-T4THwne8IE",
"RD-T4THwne8IE",
nil,
},
{
"fail-1-playlist-id-44-char",
"https://www.youtube.com/watch?v=9UL390els7M&list=PLqAfPOrmacr963ATEroh67fbvjmTzTEx5X1212404244", "",
ErrInvalidPlaylist,
},
{
"fail-2",
"", "",
ErrInvalidPlaylist,
},
{
"fail-3",
"awevqevqwev", "",
ErrInvalidPlaylist,
},
}
for _, v := range tests {
t.Run(v.name, func(t *testing.T) {
id, err := extractPlaylistID(v.url)
assert.Equal(t, v.expectedError, err)
assert.Equal(t, v.expectedID, id)
})
}
}