c26b06f1cc
Go 控制面(SQLite + REST API)嵌入 Mihomo 数据面,Vue 3 多语言 Web 管理台。 含订阅/节点/规则/出站/监控/日志、OpenAPI、API Key、Gitea Actions CI 与开源文档; CI 使用 ubuntu-latest runner,Go/Docker 步骤走国内镜像与 shell,避免 GitHub 下载超时。 Co-authored-by: Cursor <cursoragent@cursor.com>
36 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|