feat(widget): 优化访客在线轨迹、GeoIP与多站点渠道
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeSiteDomain(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"https://www.Example.com/path": "www.example.com",
|
||||
"shop.example.com:443": "shop.example.com",
|
||||
"localhost:5173": "localhost",
|
||||
"": "",
|
||||
"invalid host": "",
|
||||
}
|
||||
for input, want := range cases {
|
||||
if got := NormalizeSiteDomain(input); got != want {
|
||||
t.Fatalf("NormalizeSiteDomain(%q)=%q, want %q", input, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSiteDomainMatches(t *testing.T) {
|
||||
if !SiteDomainMatches("example.com", "https://www.example.com/product/1") {
|
||||
t.Fatal("www 与主域应视为同一站点")
|
||||
}
|
||||
if SiteDomainMatches("shop.example.com", "https://www.example.com") {
|
||||
t.Fatal("不同子域不应匹配")
|
||||
}
|
||||
if !SiteDomainMatches("", "https://any.example.com") {
|
||||
t.Fatal("未配置域名时应允许任意站点")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user