galched-bot/modules/youtube/requester_test.go
alexvanin f0f31a8415 Add twitch point song requests to the bot
This commits adds new feature for galchedbot: video requests
in the twitch chat via highlighted chat messages. This messages
parsed by the bot and added to the video queue, that can be
accessed by the dedicated web server. Video queue requires
authorization based on random token added to the cookies.
2020-01-11 22:38:51 +03:00

67 lines
1.5 KiB
Go

package youtube
import (
"io/ioutil"
"testing"
)
func TestPlayground(t *testing.T) {
youtubeTokenPath := "../../tokens/.youtubetoken"
youtubetoken, err := ioutil.ReadFile(youtubeTokenPath)
if err != nil {
t.Errorf("cannot read youtube token: %v", err)
}
_ = youtubetoken
}
func TestFetchID(t *testing.T) {
positiveCases := [][]string{
{
"https://www.youtube.com/watch?v=_v5IzvVTw7A&feature=feedrec_grec_index",
"_v5IzvVTw7A",
},
{
"https://www.youtube.com/watch?v=_v5IzvVTw7A#t=0m10s",
"_v5IzvVTw7A",
},
{
"https://www.youtube.com/embed/_v5IzvVTw7A?rel=0",
"_v5IzvVTw7A",
},
{
"https://www.youtube.com/watch?v=_v5IzvVTw7A ", // multiple spaces in the end
"_v5IzvVTw7A",
},
{
"https://youtu.be/_v5IzvVTw7A",
"_v5IzvVTw7A",
},
{
"https://www.youtube.com/watch?v=PCp2iXA1uLE&list=PLvx4lPhqncyf10ymYz8Ph8EId0cafzhdZ&index=2&t=0s",
"PCp2iXA1uLE",
},
}
negativeCases := []string{
"https://youtu.be/_vIzvVTw7A", // short video
"https://vimeo.com/_v5IzvVTw7A", // incorrect domain
"youtube prime video",
}
for _, testCase := range positiveCases {
res, err := videoID(testCase[0])
if err != nil {
t.Errorf("expecting error: <nil>, got: <%v>, url: %s\n", err, testCase[0])
}
if res != testCase[1] {
t.Errorf("expecting result: %s, got: %s\n", testCase[0], res)
}
}
for _, testCase := range negativeCases {
_, err := videoID(testCase)
if err == nil {
t.Error("expecting error: <non nil>, got: <nil>")
}
}
}