-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathchat_crawler_detector_test.go
46 lines (43 loc) · 1.18 KB
/
chat_crawler_detector_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
package main
import "testing"
func TestChatCrawlerDetector_IsChatCrawler(t *testing.T) {
tests := []struct {
name string
userAgent string
want bool
}{
{
name: "slack",
userAgent: "Slackbot-LinkExpanding 1.0 (+https://api.slack.com/robots)",
want: true,
},
{
name: "google",
userAgent: "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
want: true,
},
{
name: "twitter",
userAgent: "Twitterbot/1.0",
want: true,
},
{
name: "iMessage",
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4 facebookexternalhit/1.1 Facebot Twitterbot/1.0",
want: true,
},
{
name: "normal browser request",
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.4 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.4",
want: false,
},
}
c := NewChatCrawlerDetector()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := c.IsChatCrawler(tt.userAgent); got != tt.want {
t.Errorf("IsChatCrawler() = %v, want %v", got, tt.want)
}
})
}
}