Files
Prism/internal/rulematch/matcher_test.go
T
renjue fe8ea784d0
CI / docker (push) Successful in 2m54s
feat: Prism HTTP/SOCKS5 代理网关及管理台
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 15:58:28 +08:00

36 lines
1.1 KiB
Go

package rulematch
import (
"testing"
"github.com/prism/proxy/internal/store"
)
func TestMatchDomainSuffix(t *testing.T) {
rules := []store.Rule{
{Priority: 10, RuleType: "DOMAIN-SUFFIX", Payload: "google.com", Target: "PROXY", Source: "manual", Enabled: true},
{Priority: 20, RuleType: "DOMAIN", Payload: "exact.com", Target: "DIRECT", Source: "manual", Enabled: true},
}
res := Match(rules, "DIRECT", "https://www.google.com/search", true)
if !res.Matched || res.RuleType != "DOMAIN-SUFFIX" || res.Target != "PROXY" {
t.Fatalf("unexpected: %+v", res)
}
}
func TestMatchFallback(t *testing.T) {
rules := []store.Rule{
{Priority: 10, RuleType: "DOMAIN", Payload: "other.com", Target: "PROXY", Source: "manual", Enabled: true},
}
res := Match(rules, "country:HK", "https://example.com", true)
if res.RuleType != "MATCH" || res.Target != "country:HK" {
t.Fatalf("unexpected: %+v", res)
}
}
func TestParseHost(t *testing.T) {
host, port := ParseHost("https://foo.com:8443/path")
if host != "foo.com" || port != "8443" {
t.Fatalf("got %q %q", host, port)
}
}