Files
Prism/internal/rulematch/matcher_test.go
T
rose_cat707 fc3a66dc83
CI / docker (push) Has been cancelled
CI / test (push) Has been cancelled
feat: Prism HTTP/SOCKS5 代理网关及管理台
Go 控制面(SQLite + REST API)嵌入 Mihomo 数据面,Vue 3 多语言 Web 管理台。
含订阅/节点/规则/出站/监控/日志、OpenAPI、API Key、Gitea Actions CI(runs-on: ubuntu-latest)
与开源文档;镜像发布至 git.rc707blog.top Container Registry。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 13:41:56 +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)
}
}