package service import "testing" func TestClassifyBot(t *testing.T) { cases := []struct { ua string want string }{ {"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", "Googlebot"}, {"Mozilla/5.0 (compatible; bingbot/2.0)", "bingbot"}, {"Mozilla/5.0 (compatible; Baiduspider/2.0)", "Baiduspider"}, {"Mozilla/5.0 (compatible; Bytespider; https://zhanzhang.toutiao.com/)", "Bytespider"}, {"curl/8.4.0", "curl"}, {"Wget/1.21", "Wget"}, {"python-requests/2.31", "python-requests"}, {"Go-http-client/2.0", "Go-http-client"}, {"GPTBot/1.0", "GPTBot"}, {"ClaudeBot/1.0", "ClaudeBot"}, {"HeadlessChrome/120", "HeadlessChrome"}, // 人类浏览器不命中 {"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36", ""}, {"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148 Safari/604.1", ""}, {"", ""}, } for _, c := range cases { if got := ClassifyBot(c.ua); got != c.want { t.Errorf("ClassifyBot(%q) = %q, want %q", c.ua, got, c.want) } } }