feat: dedupe generic rules

This commit is contained in:
2026-07-20 17:42:48 +08:00
parent 8c574bf054
commit 69e7d05c10
2 changed files with 82 additions and 11 deletions

View File

@ -58,3 +58,36 @@ func TestDedupeGeoIPRuleNonList(t *testing.T) {
t.Fatalf("expected nil passthrough, got %#v", got)
}
}
func TestDedupeGenericRule(t *testing.T) {
rules := []interface{}{
"DOMAIN,example.com,sub-a | Proxy",
"DOMAIN-SUFFIX,google.com,sub-a | Proxy",
"DOMAIN,example.com,sub-b | Proxy",
"IP-CIDR,10.0.0.0/8,DIRECT,no-resolve",
"DOMAIN-SUFFIX,google.com,sub-b | Proxy",
"IP-CIDR,10.0.0.0/8,sub-b | Proxy",
"GEOIP,CN,DIRECT",
"MATCH,sub-a | Auto",
}
got := dedupeGenericRule(rules)
want := []interface{}{
"DOMAIN,example.com,sub-a | Proxy",
"DOMAIN-SUFFIX,google.com,sub-a | Proxy",
"IP-CIDR,10.0.0.0/8,DIRECT,no-resolve",
"GEOIP,CN,DIRECT",
"MATCH,sub-a | Auto",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %#v, want %#v", got, want)
}
}
func TestDedupeGenericRuleNonList(t *testing.T) {
if got := dedupeGenericRule(nil); got != nil {
t.Fatalf("expected nil passthrough, got %#v", got)
}
}