31 lines
906 B
Go
31 lines
906 B
Go
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("未配置域名时应允许任意站点")
|
|
}
|
|
}
|