package analytics import "testing" func TestIsBot(t *testing.T) { yes := []string{ "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Mozilla/5.0 (compatible; bingbot/2.0)", "curl/8.4.0", "Wget/1.21", "python-requests/2.31", "Go-http-client/1.1", "Mozilla/5.0 HeadlessChrome/120", "facebookexternalhit/1.1", "Slackbot-LinkExpanding", "AhrefsBot/7.0", "", } no := []string{ "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36", "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148", } for _, ua := range yes { if !IsBot(ua) { t.Errorf("IsBot(%q) = false", ua) } } for _, ua := range no { if IsBot(ua) { t.Errorf("IsBot(%q) = true", ua) } } }