2024-02-03 11:05:10 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestShouldPing(t *testing.T) {
|
2024-02-09 14:31:04 +00:00
|
|
|
cfg := MetricConfig{
|
2024-02-03 11:05:10 +00:00
|
|
|
Enabled: true,
|
|
|
|
Url: "",
|
|
|
|
BotUserAgents: &[]regexp.Regexp{
|
|
|
|
*regexp.MustCompile("random-bot/.*"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.ShouldSendMetrics("/index.html", "random-bot/v23.5") {
|
|
|
|
t.Fatalf("Accepted bot user-agent")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !cfg.ShouldSendMetrics("/index.html", "Firefox/...") {
|
|
|
|
t.Fatalf("Rejected real user-agent")
|
|
|
|
}
|
|
|
|
}
|