carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package analytics
2
3import "testing"
4
5func TestIsBot(t *testing.T) {
6 yes := []string{
7 "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
8 "Mozilla/5.0 (compatible; bingbot/2.0)", "curl/8.4.0", "Wget/1.21",
9 "python-requests/2.31", "Go-http-client/1.1", "Mozilla/5.0 HeadlessChrome/120",
10 "facebookexternalhit/1.1", "Slackbot-LinkExpanding", "AhrefsBot/7.0", "",
11 }
12 no := []string{
13 "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15",
14 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36",
15 "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148",
16 }
17 for _, ua := range yes {
18 if !IsBot(ua) {
19 t.Errorf("IsBot(%q) = false", ua)
20 }
21 }
22 for _, ua := range no {
23 if IsBot(ua) {
24 t.Errorf("IsBot(%q) = true", ua)
25 }
26 }
27}
28