Files
go-otel/internal/uaclass/uaclass_test.go
T
mats 8824af8699
Build and Publish / Metadata (push) Successful in 2s
Build and Publish / BuildAndDeployAmd64 (push) Failing after 4s
fixes
2026-09-20 09:52:49 +02:00

38 lines
1.6 KiB
Go

package uaclass
import "testing"
func TestClassify(t *testing.T) {
cases := []struct{ ua, class, name string }{
{"", None, ""},
{"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; GPTBot/1.2; +https://openai.com/gptbot)", AICrawler, "GPTBot"},
{"Mozilla/5.0 (compatible; ClaudeBot/1.0; +claudebot@anthropic.com)", AICrawler, "ClaudeBot"},
{"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko); compatible; ChatGPT-User/1.0", AIAgent, "ChatGPT-User"},
{"claude-code/2.1.0 (external, cli)", AIAgent, "Claude Code"},
{"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)", SearchCrawler, "Googlebot"},
{"Mozilla/5.0 (compatible; AhrefsBot/7.0)", SEOCrawler, "AhrefsBot"},
{"Uptime-Kuma/1.23.11", Monitor, "Uptime-Kuma"},
{"kube-probe/1.31", Monitor, "kube-probe"},
{"CameraScannerV3/1.0", ScanTool, "CameraScanner"},
{"Go-http-client/2.0", Library, "Go-http-client"},
{"node", Library, "node"},
{"curl/8.5.0", Library, "curl"},
{"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36", Browser, ""},
{"Mozilla/5.0 (compatible; SomeNewFooBot/3.1)", OtherBot, ""},
{"Mozilla/5.0 (Macintosh) Nodeblock", Browser, ""}, // "node" must not match inside a browser UA
{"weird-thing", Unknown, ""},
}
for _, c := range cases {
got := Classify(c.ua)
if got.Class != c.class || got.Name != c.name {
t.Errorf("Classify(%q) = %+v, want %s/%s", c.ua, got, c.class, c.name)
}
}
}
func TestIsBot(t *testing.T) {
if !IsBot(AICrawler) || IsBot(Browser) || IsBot(None) || IsBot(Unknown) {
t.Fatal("IsBot mismatch")
}
}