Files
ss/internal/corecfg/manager_test.go
2026-07-20 17:42:48 +08:00

94 lines
2.0 KiB
Go

package corecfg
import (
"reflect"
"testing"
)
func TestDedupeMatchRule(t *testing.T) {
rules := []interface{}{
"DOMAIN,example.com,sub-a | Proxy",
"MATCH,sub-a | Auto",
"DOMAIN,other.com,sub-b | Proxy",
"MATCH,sub-b | Auto",
}
got := dedupeMatchRule(rules)
want := []interface{}{
"DOMAIN,example.com,sub-a | Proxy",
"DOMAIN,other.com,sub-b | Proxy",
"MATCH,all proxies",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %#v, want %#v", got, want)
}
}
func TestDedupeMatchRuleNonList(t *testing.T) {
if got := dedupeMatchRule(nil); got != nil {
t.Fatalf("expected nil passthrough, got %#v", got)
}
}
func TestDedupeGeoIPRule(t *testing.T) {
rules := []interface{}{
"GEOIP,CN,DIRECT",
"DOMAIN,example.com,sub-a | Proxy",
"GEOIP,CN,sub-b | Proxy,no-resolve",
"GEOIP,JP,sub-b | Proxy",
}
got := dedupeGeoIPRule(rules)
want := []interface{}{
"DOMAIN,example.com,sub-a | Proxy",
"GEOIP,CN,sub-b | Proxy,no-resolve",
"GEOIP,JP,sub-b | Proxy",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %#v, want %#v", got, want)
}
}
func TestDedupeGeoIPRuleNonList(t *testing.T) {
if got := dedupeGeoIPRule(nil); got != nil {
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)
}
}