新增对象存储/账单/保留IP模块,删桶并发提速与成本增强
CI / test (push) Successful in 33s

This commit is contained in:
2026-07-21 12:11:05 +08:00
parent 9cfde8b702
commit f40f2a20e8
44 changed files with 7788 additions and 54 deletions
+57
View File
@@ -29,6 +29,63 @@ func TestTransportForStageTimeouts(t *testing.T) {
if tr.TLSHandshakeTimeout != proxyTLSHandshakeTimeout {
t.Fatalf("TLSHandshakeTimeout = %v, 期望 %v", tr.TLSHandshakeTimeout, proxyTLSHandshakeTimeout)
}
if tr.MaxIdleConnsPerHost != proxyMaxIdleConnsPerHost || tr.IdleConnTimeout != proxyIdleConnTimeout {
t.Fatalf("连接池参数未设置: PerHost=%d IdleTimeout=%v", tr.MaxIdleConnsPerHost, tr.IdleConnTimeout)
}
})
}
}
func TestProxyHTTPClientReuse(t *testing.T) {
tests := []struct {
name string
a, b *ProxySpec
wantSame bool
}{
{
name: "同配置复用同一实例",
a: &ProxySpec{Type: "socks5", Host: "10.0.0.1", Port: 1080},
b: &ProxySpec{Type: "socks5", Host: "10.0.0.1", Port: 1080},
wantSame: true,
},
{
name: "不同配置各自实例",
a: &ProxySpec{Type: "socks5", Host: "10.0.0.1", Port: 1080},
b: &ProxySpec{Type: "socks5", Host: "10.0.0.2", Port: 1080},
},
{
name: "同地址不同凭据不复用",
a: &ProxySpec{Type: "socks5", Host: "10.0.0.1", Port: 1080, Username: "u1", Password: "p1"},
b: &ProxySpec{Type: "socks5", Host: "10.0.0.1", Port: 1080, Username: "u2", Password: "p2"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ca, cb := proxyHTTPClient(tt.a), proxyHTTPClient(tt.b)
if ca == nil || cb == nil {
t.Fatal("proxyHTTPClient 返回 nil")
}
if (ca == cb) != tt.wantSame {
t.Fatalf("实例复用 = %v, 期望 %v", ca == cb, tt.wantSame)
}
})
}
}
func TestProxyHTTPClientInvalidSpec(t *testing.T) {
tests := []struct {
name string
spec *ProxySpec
}{
{name: "nil 配置", spec: nil},
{name: "缺 host", spec: &ProxySpec{Type: "socks5", Port: 1080}},
{name: "非法端口", spec: &ProxySpec{Type: "socks5", Host: "10.0.0.1"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if c := proxyHTTPClient(tt.spec); c != nil {
t.Fatalf("非法配置应返回 nil,得到 %v", c)
}
})
}
}