forked from magunetto/moviemagnetbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_test.go
75 lines (64 loc) · 2.44 KB
/
bot_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
75
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFindDoubanMovieURLsOK(t *testing.T) {
urls := findDoubanMovieURLs("view-source:https://movie.douban.com/subject/22265634/?from=showing")
assert.Equal(t, []string{"https://movie.douban.com/subject/22265634"}, urls)
}
func TestFindDoubanMovieURLsMultiple(t *testing.T) {
urls := findDoubanMovieURLs(`
https://movie.douban.com/subject/22265634/?from=showing
https://movie.douban.com/subject/22265635/?from=showing
https://movie.douban.com/subject/22265636/?from=showing
`)
assert.Len(t, urls, 3)
assert.Equal(t, []string{
"https://movie.douban.com/subject/22265634",
"https://movie.douban.com/subject/22265635",
"https://movie.douban.com/subject/22265636",
}, urls)
}
func TestFindDoubanMovieURLsMissing(t *testing.T) {
urls := findDoubanMovieURLs("view-source:https://movie.douban2.com/subject/22265634/?from=showing")
assert.Len(t, urls, 0)
}
func TestFindIMDbIDsOK(t *testing.T) {
ids := findIMDbIDs(`<span class="pl">IMDb链接:</span> <a href="http://www.imdb.com/title/tt2527336" target="_blank" rel="nofollow">`)
assert.Equal(t, []string{"tt2527336"}, ids)
}
func TestFindIMDbIDsMultiple(t *testing.T) {
ids := findIMDbIDs(`
<a href="http://www.imdb.com/title/tt2527336" target="_blank" rel="nofollow">
<a href="http://www.imdb.com/title/tt2527337" target="_blank" rel="nofollow">
<a href="http://www.imdb.com/title/tt2527338" target="_blank" rel="nofollow">`)
assert.Len(t, ids, 3)
assert.Equal(t, []string{
"tt2527336",
"tt2527337",
"tt2527338",
}, ids)
}
func TestFindIMDbIDsMissing(t *testing.T) {
ids := findIMDbIDs(`<span class="pl">IMDb链接:</span> <a href="http://www.imdb.com/title/tt252733" target="_blank" rel="nofollow">`)
assert.Len(t, ids, 0)
}
func TestSearchIMDbIDsFromMessageIMDbURLOK(t *testing.T) {
ids, err := searchIMDbIDsFromMessage(`http://www.imdb.com/title/tt2527336`)
assert.NoError(t, err)
assert.Equal(t, []string{"tt2527336"}, ids)
}
func TestSearchIMDbIDsFromMessageMultipleURLOK(t *testing.T) {
ids, err := searchIMDbIDsFromMessage(`
http://www.imdb.com/title/tt2527336
https://movie.douban.com/subject/22265634
`)
assert.NoError(t, err)
assert.Equal(t, []string{"tt2527336", "tt2527336"}, ids)
}
func TestSearchIMDbIDsFromMessageDoubanURLOK(t *testing.T) {
ids, err := searchIMDbIDsFromMessage(`https://movie.douban.com/subject/22265634/`)
assert.NoError(t, err)
assert.Equal(t, []string{"tt2527336"}, ids)
}