1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-15 16:20:08 +00:00

fix(status): improve proxy detection and add parser tests

This commit is contained in:
tw93
2026-02-07 17:43:59 +08:00
parent 9ec0db9245
commit 425f23a739
3 changed files with 222 additions and 23 deletions

View File

@@ -0,0 +1,60 @@
package main
import "testing"
func TestCollectProxyFromEnvSupportsAllProxy(t *testing.T) {
env := map[string]string{
"ALL_PROXY": "socks5://127.0.0.1:7890",
}
getenv := func(key string) string {
return env[key]
}
got := collectProxyFromEnv(getenv)
if !got.Enabled {
t.Fatalf("expected proxy enabled")
}
if got.Type != "SOCKS" {
t.Fatalf("expected SOCKS type, got %s", got.Type)
}
if got.Host != "127.0.0.1:7890" {
t.Fatalf("unexpected host: %s", got.Host)
}
}
func TestCollectProxyFromScutilOutputPAC(t *testing.T) {
out := `
<dictionary> {
ProxyAutoConfigEnable : 1
ProxyAutoConfigURLString : http://127.0.0.1:6152/proxy.pac
}`
got := collectProxyFromScutilOutput(out)
if !got.Enabled {
t.Fatalf("expected proxy enabled")
}
if got.Type != "PAC" {
t.Fatalf("expected PAC type, got %s", got.Type)
}
if got.Host != "127.0.0.1:6152" {
t.Fatalf("unexpected host: %s", got.Host)
}
}
func TestCollectProxyFromScutilOutputHTTPHostPort(t *testing.T) {
out := `
<dictionary> {
HTTPEnable : 1
HTTPProxy : 127.0.0.1
HTTPPort : 7890
}`
got := collectProxyFromScutilOutput(out)
if !got.Enabled {
t.Fatalf("expected proxy enabled")
}
if got.Type != "HTTP" {
t.Fatalf("expected HTTP type, got %s", got.Type)
}
if got.Host != "127.0.0.1:7890" {
t.Fatalf("unexpected host: %s", got.Host)
}
}