Files
Ant-Browser/backend/internal/proxy/xray_validate_test.go
T
Ant Browser Release Bot 6f58a6c19a publish: 1.0.0 snapshot (bad2ec1)
channel: master
version: 1.0.0
source-ref: master
published-at-utc: 2026-03-13T15:19:28Z
2026-03-13 23:19:29 +08:00

37 lines
929 B
Go

package proxy
import (
"ant-chrome/backend/internal/config"
"strings"
"testing"
)
func TestValidateProxyConfigInvalidRawString(t *testing.T) {
ok, msg := ValidateProxyConfig("not-a-proxy-config", nil, "")
if ok {
t.Fatalf("expected invalid raw string to fail validation")
}
if !strings.Contains(msg, "解析失败") {
t.Fatalf("unexpected message: %s", msg)
}
}
func TestValidateProxyConfigMissingProxyId(t *testing.T) {
ok, msg := ValidateProxyConfig("", []config.BrowserProxy{
{ProxyId: "p1", ProxyConfig: "http://127.0.0.1:7890"},
}, "missing-proxy")
if ok {
t.Fatalf("expected missing proxyId to fail validation")
}
if !strings.Contains(msg, "不存在") {
t.Fatalf("unexpected message: %s", msg)
}
}
func TestValidateProxyConfigStandardProxy(t *testing.T) {
ok, msg := ValidateProxyConfig("socks5://127.0.0.1:1080", nil, "")
if !ok {
t.Fatalf("expected standard proxy to pass: %s", msg)
}
}