返回 DeepSeek-Reasonix
sysproxy_test.go
根目录 / internal / sysproxy / sysproxy_test.go
1 package sysproxy
2
3 import "testing"
4
5 func TestParseProxyList(t *testing.T) {
6 for _, tc := range []struct {
7 name, list, scheme, want string
8 }{
9 {"single all-protocol", "proxy.example.com:8080", "https", "http://proxy.example.com:8080"},
10 {"per-protocol https", "http=p1:80;https=p2:443", "https", "http://p2:443"},
11 {"per-protocol http", "http=p1:80;https=p2:443", "http", "http://p1:80"},
12 {"scheme miss falls back to bare", "p0:3128;ftp=p1:21", "https", "http://p0:3128"},
13 {"strips scheme prefix", "http://p:8080", "https", "http://p:8080"},
14 {"empty", "", "https", ""},
15 {"only other protocol, no bare", "ftp=p:21", "https", ""},
16 } {
17 t.Run(tc.name, func(t *testing.T) {
18 got := parseProxyList(tc.list, tc.scheme)
19 if tc.want == "" {
20 if got != nil {
21 t.Fatalf("got %v, want nil", got)
22 }
23 return
24 }
25 if got == nil || got.String() != tc.want {
26 t.Fatalf("got %v, want %s", got, tc.want)
27 }
28 })
29 }
30 }
31
32 func TestBypassed(t *testing.T) {
33 for _, tc := range []struct {
34 host, bypass string
35 want bool
36 }{
37 {"api.deepseek.com", "<local>", false},
38 {"intranet", "<local>", true},
39 {"host.corp.local", "*.corp.local", true},
40 {"api.deepseek.com", "*.corp.local;<local>", false},
41 {"api.deepseek.com", "api.deepseek.com", true},
42 {"API.DeepSeek.com", "api.deepseek.com", true},
43 {"api.deepseek.com", "", false},
44 } {
45 if got := bypassed(tc.host, tc.bypass); got != tc.want {
46 t.Errorf("bypassed(%q, %q) = %v, want %v", tc.host, tc.bypass, got, tc.want)
47 }
48 }
49 }
50
50 lines GO