chore: remove trailing blank lines and clean up whitespace

This commit is contained in:
xfy 2026-06-03 18:08:34 +08:00
parent 5ee83f6a69
commit 6f17bbad7e
78 changed files with 63 additions and 469 deletions

View File

@ -44,5 +44,3 @@ func defaultConfig() *Config {
encodeSortKeys: defaultEncodeSortKeys,
}
}

View File

@ -77,5 +77,3 @@ func Loader(L *glua.LState) int {
L.Push(mod)
return 1
}

View File

@ -371,19 +371,6 @@ func TestPrintVersion(t *testing.T) {
}
}
// TestVersionVariables 测试版本变量默认值
func TestVersionVariables(t *testing.T) {
if version.Version != "dev" {
@ -434,25 +421,6 @@ func TestAppFields(t *testing.T) {
}
}
// TestGenerateConfig_ErrorCase 测试生成配置时的错误情况
// 注意config.GenerateConfigYAML 正常情况下不会失败,
// 但我们测试文件写入失败的情况
@ -475,14 +443,6 @@ func TestGenerateConfig_ErrorCase(t *testing.T) {
})
}
// TestApp_Run_WithValidConfig 测试 App.Run 加载有效配置
// 注意:此测试验证配置加载路径,但由于服务器启动会阻塞,
// 我们通过子进程测试或使用 short 标志跳过完整运行

View File

@ -6,6 +6,3 @@
//
// 作者xfy
package app

View File

@ -618,5 +618,3 @@ func TestProxyCacheDeleteByPatternNoMatch(t *testing.T) {
t.Error("Original entry should still exist")
}
}

View File

@ -134,13 +134,8 @@ servers:
})
}
// TestConfigMethods 测试 Config 结构体的方法。
func TestProxyBufferingConfig_ParseBuffers(t *testing.T) {
tests := []struct {
name string

View File

@ -253,5 +253,3 @@ func TestGenerateConfigYAMLContainsAllSections(t *testing.T) {
}
}
}

View File

@ -202,5 +202,3 @@ func (a *FastHTTPHandlerAdapter) convertResponse(ctx *fasthttp.RequestCtx, w htt
}
}
}

View File

@ -205,7 +205,6 @@ func TestTLSHandshakeFailure(t *testing.T) {
// TestALPNNegotiationH2 测试 ALPN 协商选择 h2。
// TestALPNHTTP11Fallback 测试 ALPN 协商回退到 HTTP/1.1。
func TestALPNHTTP11Fallback(t *testing.T) {
cert, _ := generateTestCert(t)
@ -270,10 +269,8 @@ func TestALPNHTTP11Fallback(t *testing.T) {
// TestTLSListenerWrapper 测试 TLS 监听器包装。
// TestTLSListenerExistingProtos 测试已有 NextProtos 的情况。
// TestServeHTTP1Fallback 测试 HTTP/1.1 回退。
func TestServeHTTP1Fallback(t *testing.T) {
handler := func(ctx *fasthttp.RequestCtx) {
@ -375,6 +372,3 @@ func (m *mockTestConn) SetReadDeadline(_ time.Time) error { return nil }
func (m *mockTestConn) SetWriteDeadline(_ time.Time) error {
return nil
}

View File

@ -329,5 +329,3 @@ func (p *connectionPool) closeAll() {
}
p.conns = make(map[string][]net.Conn)
}

View File

@ -420,7 +420,6 @@ func BenchmarkHTTP2RequestRoundTrip_WithBody_Parallel(b *testing.B) {
// 测量 ValidateSettings 函数的开销,用于了解
// 配置验证阶段的性能成本。
// BenchmarkHTTP2AdapterWithHPACKHeaders 测试带 HPACK 编码头部的适配器性能
//
// 模拟 HTTP/2 场景下经过 HPACK 压缩和解压缩后的头部转换开销。

View File

@ -148,5 +148,3 @@ func (a *Adapter) convertResponse(ctx *fasthttp.RequestCtx, w http.ResponseWrite
_, _ = w.Write(body)
}
}

View File

@ -208,5 +208,3 @@ func (s *Server) Stop() error {
logging.Info().Msg("HTTP/3 server stopped")
return nil
}

View File

@ -122,8 +122,4 @@ func TestNewServer_Success(t *testing.T) {
// TestStart_AlreadyRunning 测试启动已运行的服务器
// TestStart_InvalidListenAddress 测试无效监听地址

View File

@ -31,7 +31,6 @@ import (
"github.com/valyala/fasthttp"
"github.com/valyala/fasthttp/fasthttputil"
"rua.plus/lolly/internal/testutil"
"rua.plus/lolly/internal/cache"
"rua.plus/lolly/internal/config"
"rua.plus/lolly/internal/handler"
@ -43,6 +42,7 @@ import (
"rua.plus/lolly/internal/middleware/rewrite"
"rua.plus/lolly/internal/middleware/security"
"rua.plus/lolly/internal/proxy"
"rua.plus/lolly/internal/testutil"
)
// generateTestCert 生成自签名测试证书(服务器认证)。

View File

@ -159,5 +159,3 @@ func (m *SlowStartManager) updateEffectiveWeights() {
}
}
}

View File

@ -43,5 +43,3 @@ func TestTarget_GetEffectiveWeight(t *testing.T) {
})
}
}

View File

@ -257,5 +257,3 @@ func headersToLuaTable(L *glua.LState, headers map[string]string) *glua.LTable {
}
return table
}

View File

@ -390,5 +390,3 @@ func (api *ngxLogAPI) luaRedirect(L *glua.LState) int {
L.RaiseError("%s", "ngx.redirect: "+uri)
return 0
}

View File

@ -593,5 +593,3 @@ func (api *ngxReqAPI) GetPerformanceRatio() float64 {
func (api *ngxReqAPI) ResetMetrics() {
api.metrics = ngxReqMetrics{}
}

View File

@ -197,5 +197,3 @@ func (api *ngxRespAPI) SetHeader(name, value string) {
api.headersCache = nil
api.headersCacheOnce = sync.Once{}
}

View File

@ -261,5 +261,3 @@ func (api *ngxVarAPI) GetVariable(name string) (string, bool) {
value := api.getVariable(name)
return value, value != ""
}

View File

@ -90,5 +90,3 @@ func ParsePhase(s string) (Phase, error) {
return PhaseInit, fmt.Errorf("unknown phase: %s", s)
}
}

View File

@ -21,5 +21,3 @@ type APIMethod struct {
// Func Lua 函数实现
Func func(*glua.LState) int
}

View File

@ -263,5 +263,3 @@ func (e *LocationEngine) checkConflict(path, locationType string) error {
e.registeredPaths[path] = locationType
return nil
}

View File

@ -337,7 +337,3 @@ func TestLocationEngine_MarkInitialized(t *testing.T) {
t.Error("AddNamed should fail after initialized")
}
}

View File

@ -33,5 +33,3 @@ func NewNamedMatcher(name string, handler fasthttp.RequestHandler) *NamedMatcher
handler: handler,
}
}

View File

@ -275,5 +275,3 @@ func ParseSize(sizeStr string) (int64, error) {
return int64(value * multiplier), nil
}

View File

@ -9,8 +9,8 @@ import (
"testing"
"github.com/valyala/fasthttp"
"rua.plus/lolly/internal/testutil"
"rua.plus/lolly/internal/config"
"rua.plus/lolly/internal/testutil"
)
// BenchmarkGzipCompress_1KB 测试 gzip 压缩 1KB 数据的性能。

View File

@ -18,8 +18,8 @@ import (
"testing"
"github.com/valyala/fasthttp"
"rua.plus/lolly/internal/testutil"
"rua.plus/lolly/internal/config"
"rua.plus/lolly/internal/testutil"
)
// BenchmarkGzipPool_GetPut 测试 gzip.Writer 池直接操作。

View File

@ -5,8 +5,6 @@
// 作者xfy
package netutil
// StripPort 从 Host 头中移除端口号。
//
// 支持 IPv4 和 IPv6 格式:
@ -44,5 +42,3 @@ func StripPort(host string) string {
return host
}

View File

@ -35,5 +35,3 @@ func TestStripPort(t *testing.T) {
})
}
}

View File

@ -278,5 +278,3 @@ func (h *HealthChecker) MarkHealthy(target *loadbalance.Target) {
h.slowStartManager.OnTargetHealthy(target)
}
}

View File

@ -25,10 +25,6 @@ import (
"rua.plus/lolly/internal/loadbalance"
)
// TestCheckTarget 测试 checkTarget 方法。
func TestCheckTarget(t *testing.T) {
t.Run("健康响应", func(t *testing.T) {

View File

@ -990,5 +990,3 @@ func isWebSocketRequest(ctx *fasthttp.RequestCtx) bool {
upgrade := ctx.Request.Header.Peek("Upgrade")
return strings.EqualFold(string(upgrade), "websocket")
}

View File

@ -9,9 +9,9 @@ import (
"github.com/valyala/fasthttp"
"github.com/valyala/fasthttp/fasthttputil"
"rua.plus/lolly/internal/testutil"
"rua.plus/lolly/internal/config"
"rua.plus/lolly/internal/loadbalance"
"rua.plus/lolly/internal/testutil"
"rua.plus/lolly/internal/variable"
)

View File

@ -193,5 +193,3 @@ func (p *Proxy) getResolverTTL() time.Duration {
// 这里返回默认值
return 30 * time.Second
}

View File

@ -120,66 +120,45 @@ func TestSetResolver(t *testing.T) {
// TestGetResolverStats_NoResolver 测试没有解析器时返回空统计。
// TestGetResolverStats_WithResolver 测试有解析器时返回统计。
// TestStartWithResolver 测试启动代理时解析器正确启动。
// TestStartResolverFails 测试解析器启动失败时代理返回错误。
// TestStartIdempotent 测试 Start 是幂等的。
// TestStopIdempotent 测试 Stop 是幂等的。
// TestStopWithoutResolver 测试没有解析器时停止代理。
// TestRefreshDNS_Success 测试 DNS 刷新成功场景。
// TestRefreshDNS_LookupError 测试 DNS 刷新时查找失败场景。
// TestRefreshDNS_NoResolver 测试没有解析器时刷新不执行任何操作。
// TestRefreshDNS_IPAddressTarget 测试 IP 类型的目标不需要解析。
// TestRefreshDNS_RecentlyResolved 测试最近已解析的目标不需要再次解析。
// TestRefreshDNS_ExpiredResolve 测试 TTL 过期后需要重新解析。
// 该测试验证 TTL 过期检查的正确性:
// - 短时间内(< TTL不需要重新解析
// - 长时间后(> TTL需要重新解析
// TestUpdateHostClientAddr_HTTP 测试 HTTP 目标地址更新。
// TestUpdateHostClientAddr_HTTPS 测试 HTTPS 目标地址更新。
// TestUpdateHostClientAddr_DefaultPort 测试没有端口时使用默认端口。
// TestUpdateHostClientAddr_NonExistentTarget 测试不存在的目标不更新。
// TestGetResolverTTL 测试 TTL 获取。
// TestDNSRefreshLoop_StartStop 测试 DNS 刷新循环的启动和停止。
// TestMultipleTargets_Refresh 测试多目标刷新。
// TestStopResolverFails 测试停止解析器失败时返回错误。

View File

@ -574,13 +574,10 @@ func TestGetClientIP(t *testing.T) {
// TestUpdateTargets 测试更新目标
// TestGetTargets 测试获取目标列表
// TestGetConfig 测试获取配置
// TestIsWebSocketRequest 测试WebSocket请求检测
func TestIsWebSocketRequest(t *testing.T) {
tests := []struct {
@ -840,7 +837,6 @@ func TestGetClient(t *testing.T) {
// TestProxyCache 测试代理缓存功能
// TestServeHTTP_WithPassiveHealthCheck 测试带有被动健康检查的请求转发
func TestServeHTTP_WithPassiveHealthCheck(t *testing.T) {
cfg := &config.ProxyConfig{

View File

@ -11,32 +11,16 @@
// 作者xfy
package proxy
// TestTempFileManager_ShouldUseTempFile 测试阈值判定
// TestTempFile_Write 测试临时文件写入
// TestTempFile_WriteTo 测试临时文件写入响应
// TestTempFile_Close 测试临时文件关闭和清理
// TestGetDefaultTempFileManager 测试默认临时文件管理器
// TestGlobalTempFileCleaner 测试全局临时文件清理器
// strContains 检查字符串是否包含子串

View File

@ -150,5 +150,3 @@ func (h *PurgeHandler) purgeByPattern(pattern string, method string) int {
return deleted
}

View File

@ -596,10 +596,6 @@ func TestPurgeHandler_SendError(t *testing.T) {
}
}
// TestPurgeHandler_CacheKeyWithMethod 测试带方法的缓存键。
func TestPurgeHandler_CacheKeyWithMethod(t *testing.T) {
tests := []struct {
@ -664,10 +660,6 @@ func TestPurgeHandler_checkAccess_NilContext(t *testing.T) {
})
}
// TestPurgeHandler_ServeHTTP_WithAllowList 测试带白名单的请求处理。
func TestPurgeHandler_ServeHTTP_WithAllowList(t *testing.T) {
cfg := &config.CacheAPIConfig{
@ -719,18 +711,6 @@ func TestPurgeHandler_checkAccess_WithAllowedIP(t *testing.T) {
})
}
// TestPurgeHandler_PurgeByPath_HashConsistency 测试哈希一致性。
func TestPurgeHandler_PurgeByPath_HashConsistency(t *testing.T) {
// 验证相同路径和方法产生相同哈希
@ -803,7 +783,3 @@ func TestPurgeHandler_PurgeByPattern_PatternMatching(t *testing.T) {
})
}
}

View File

@ -1221,7 +1221,6 @@ func TestServer_SetUpgradeManager(t *testing.T) {
// TestServer_GetResolver 测试获取解析器。
// TestServer_StopWithTimeout_WithListeners 测试带监听器的停止。
func TestServer_StopWithTimeout_WithListeners(t *testing.T) {
cfg := &config.Config{

View File

@ -20,8 +20,8 @@ import (
"time"
"github.com/valyala/fasthttp"
"rua.plus/lolly/internal/testutil"
"rua.plus/lolly/internal/config"
"rua.plus/lolly/internal/testutil"
)
// TestStart_Integration 测试完整的服务器启动和请求处理流程

View File

@ -28,9 +28,6 @@ type MockFastServer struct {
CloseOnShutdown bool
}
// TestDependencies 包含测试时可注入的依赖
// 使用具体指针类型,允许注入 Mock 实现
type TestDependencies struct {
@ -38,8 +35,6 @@ type TestDependencies struct {
TLSManager *ssl.TLSManager
}
// TestServerOptions 测试服务器的可选配置
type TestServerOptions struct {
MockFastServer *MockFastServer
@ -47,7 +42,3 @@ type TestServerOptions struct {
SkipListener bool
DisableMiddleware bool
}

View File

@ -8,28 +8,20 @@ import (
// TestMockFastServer_Serve 测试 MockFastServer.Serve 方法
// TestMockFastServer_ServeTLS 测试 MockFastServer.ServeTLS 方法
// TestMockFastServer_Shutdown 测试 MockFastServer.Shutdown 方法
// TestNewServerForTesting 测试 NewServerForTesting 函数
// TestNewTestServerWithOptions 测试 NewTestServerWithOptions 函数
// TestMustStartTestServer 测试 MustStartTestServer 函数
// TestTestDependencies 测试 TestDependencies 结构体
// TestTestServerOptions 测试 TestServerOptions 结构体
// TestMockFastServer_Fields 测试 MockFastServer 字段
func TestMockFastServer_Fields(t *testing.T) {
mock := &MockFastServer{

View File

@ -236,5 +236,3 @@ func listenerFile(listener net.Listener) (*os.File, error) {
return nil, fmt.Errorf("unsupported listener type: %T", listener)
}
}

View File

@ -47,10 +47,6 @@ func TestIsChild(t *testing.T) {
}
}
func TestGetInheritedListenersNoFds(t *testing.T) {
mgr := NewUpgradeManager(nil)
@ -64,10 +60,6 @@ func TestGetInheritedListenersNoFds(t *testing.T) {
}
}
// TestUpgradeSetListeners 测试监听器设置
func TestUpgradeSetListeners(t *testing.T) {
mgr := NewUpgradeManager(nil)
@ -110,7 +102,6 @@ func TestWritePid_NoPidFile(t *testing.T) {
// TestReadOldPid_InvalidContent 测试 PID 文件内容无效时的错误处理
// TestGetInheritedListeners_InvalidFds 测试 LISTEN_FDS 环境变量格式无效
func TestGetInheritedListeners_InvalidFds(t *testing.T) {
tests := []struct {
@ -155,7 +146,6 @@ func TestGetInheritedListeners_InvalidFds(t *testing.T) {
// TestWaitForShutdown_WithTimeout 测试超时行为
// TestListenerFile_TCPListener 测试从 TCP 监听器获取文件
func TestListenerFile_TCPListener(t *testing.T) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
@ -211,49 +201,35 @@ func TestGracefulUpgrade_NoListeners(t *testing.T) {
// TestNotifyOldProcess_WithCurrentPid 测试通知进程
// 注意:不能向当前进程发送 SIGQUIT会导致测试崩溃
// TestReadOldPid_EmptyFile 测试空 PID 文件
// TestNotifyOldProcess_ReadPidError 测试读取 PID 失败的情况
// TestNotifyOldProcess_ZeroPid 测试 PID 为 0 的情况
// TestNotifyOldProcess_NonExistentProcess 测试通知不存在的进程
// TestNotifyOldProcess_FindProcessError 测试 os.FindProcess 的行为
// 注意:在 Unix 系统上os.FindProcess 总是成功,即使进程不存在
// TestSetupSignalHandlers_SetsUpChannel 测试信号处理器设置
// TestSetupSignalHandlers_TriggersUpgrade 测试信号触发升级
// TestGracefulUpgrade_UnsupportedListener 测试不支持的监听器类型
// TestGracefulUpgrade_NonexistentBinary 测试不存在的二进制文件
// 注意:此测试使用 mock 监听器避免创建实际网络连接
// TestGracefulUpgrade_WithPidFile 测试升级时写入 PID 文件
// 注意:此测试使用 mock 监听器避免创建实际网络连接
// TestWaitForShutdown_ProcessExits 测试进程退出后的等待
// TestWaitForShutdown_Timeout 测试等待超时
// TestWaitForShutdown_SetsOldPid 测试 oldPid 设置
// TestListenerFile_UnixListener 测试 Unix 监听器获取文件
// 注意:跳过此测试,因为在大量测试运行时可能导致 FD 问题
func TestListenerFile_UnixListener(t *testing.T) {
@ -263,14 +239,11 @@ func TestListenerFile_UnixListener(t *testing.T) {
// TestGracefulUpgrade_MultipleListeners 测试多个监听器的升级
// 注意:使用 mock 监听器避免 FD 问题
// TestGracefulUpgrade_RelativePath 测试相对路径的二进制文件
// 注意:使用 mock 监听器避免 FD 问题
// TestWaitForShutdown_FindProcessError 测试 FindProcess 行为
// TestGetInheritedListeners_EnvPreserved 测试环境变量处理
func TestGetInheritedListeners_EnvPreserved(t *testing.T) {
t.Setenv("LISTEN_FDS", "1")
@ -286,5 +259,3 @@ func TestGetInheritedListeners_EnvPreserved(t *testing.T) {
t.Error("LISTEN_FDS env should be preserved")
}
}

View File

@ -1397,7 +1397,6 @@ func TestStartVHostMode_ModeDetection(t *testing.T) {
// TestStartVHostMode_StartIntegration 测试 startVHostMode 启动集成。
// TestStartVHostMode_VHostManagerCreation 测试 VHostManager 创建逻辑。
func TestStartVHostMode_VHostManagerCreation(t *testing.T) {
manager := NewVHostManager()

View File

@ -256,5 +256,3 @@ type ClientCertInfo struct {
DNSNames []string
Email []string
}

View File

@ -132,8 +132,6 @@ func TestParseVerifyMode(t *testing.T) {
}
}
// TestLoadCACertPool 测试 CA 证书池加载。
func TestLoadCACertPool(t *testing.T) {
// 创建临时 CA 文件
@ -171,10 +169,6 @@ func TestLoadCACertPool(t *testing.T) {
}
}
// TestClientVerifier_ConfigureTLS 测试 TLS 配置。
func TestClientVerifier_ConfigureTLS(t *testing.T) {
// 创建临时 CA 文件
@ -225,12 +219,6 @@ func TestClientVerifier_ConfigureTLS_Disabled(t *testing.T) {
}
}
// generateTestCRL 生成测试 CRL。
func generateTestCRL(t *testing.T, caCert *x509.Certificate, caKey *rsa.PrivateKey, revokedSerials []*big.Int) []byte {
t.Helper()
@ -304,12 +292,6 @@ func TestLoadCRL(t *testing.T) {
}
}
// TestVerifyConnection 测试连接验证。
func TestVerifyConnection(t *testing.T) {
// 生成测试 CA 和证书
@ -432,12 +414,6 @@ func BenchmarkLoadCACertPool(b *testing.B) {
}
}
// TestNewClientVerifier_InvalidMode 测试无效验证模式。
func TestNewClientVerifier_InvalidMode(t *testing.T) {
_, err := NewClientVerifier(config.ClientVerifyConfig{
@ -449,8 +425,6 @@ func TestNewClientVerifier_InvalidMode(t *testing.T) {
}
}
// TestNewClientVerifier_InvalidCRL 测试无效 CRL 文件。
func TestNewClientVerifier_InvalidCRL(t *testing.T) {
tempDir := t.TempDir()
@ -475,7 +449,3 @@ func TestNewClientVerifier_InvalidCRL(t *testing.T) {
t.Error("Expected error for invalid CRL file")
}
}

View File

@ -425,5 +425,3 @@ func (m *OCSPManager) GetOCSPResponse(serial string) []byte {
return nil
}
}

View File

@ -129,8 +129,6 @@ func TestOCSPGetOCSPResponse(t *testing.T) {
}
}
func TestOCSPStaleResponse(t *testing.T) {
mgr := NewOCSPManager(nil)
@ -215,8 +213,6 @@ func TestTLSManagerWithOCSPDisabled(t *testing.T) {
manager.Close()
}
func TestTLSManagerClose(t *testing.T) {
tmpDir := t.TempDir()
certPath := filepath.Join(tmpDir, "cert.pem")
@ -373,8 +369,6 @@ func TestOCSPConfigDefaults(t *testing.T) {
}
}
// TestOCSPManager_refreshAll 测试刷新所有响应
func TestOCSPManager_refreshAll(_ *testing.T) {
cfg := &OCSPConfig{
@ -413,7 +407,6 @@ func TestOCSPManager_refreshAll(_ *testing.T) {
// TestOCSPManager_GetStatus_EdgeCases 测试 GetStatus 边界情况
// TestOCSPManager_RegisterCertificate_NilCert 测试注册空证书
func TestOCSPManager_RegisterCertificate_NilCert(t *testing.T) {
mgr := NewOCSPManager(nil)
@ -494,10 +487,8 @@ func TestOCSPManager_SendOCSPRequest_Error(t *testing.T) {
// TestOCSPManager_RefreshResponse_WithExistingEntry 测试刷新已有条目的响应
// TestOCSPManager_RefreshResponse_StatusFailed 测试刷新失败后状态变化
// TestOCSPManager_FetchOCSP_NoServer 测试无 OCSP 服务器时的 fetchOCSP
func TestOCSPManager_FetchOCSP_NoServer(t *testing.T) {
mgr := NewOCSPManager(nil)

View File

@ -379,5 +379,3 @@ type SessionTicketStatus struct {
// Started 管理器是否已启动
Started bool
}

View File

@ -267,10 +267,8 @@ func TestSessionTicketManager_ApplyToTLSConfig(t *testing.T) {
// TestSessionTicketManager_StartStop 测试启动和停止。
// TestSessionTicketManager_GetStatus 测试获取状态。
// TestGenerateTicketKey 测试密钥生成函数。
func TestGenerateTicketKey(t *testing.T) {
key1, err := generateTicketKey()
@ -295,7 +293,6 @@ func TestGenerateTicketKey(t *testing.T) {
// TestSessionTicketManager_ConcurrentAccess 测试并发访问。
// BenchmarkGenerateTicketKey 基准测试密钥生成。
func BenchmarkGenerateTicketKey(b *testing.B) {
for b.Loop() {

View File

@ -414,5 +414,3 @@ func matchMarker(data []byte, marker []byte) bool {
}
return true
}

View File

@ -363,19 +363,16 @@ func BenchmarkOCSPStapling_Miss(b *testing.B) {
//
// 测量 GetStatus 方法获取证书状态信息的开销。
// BenchmarkSessionResumption 基准测试使用 Session Ticket 的会话恢复性能。
//
// 使用 ClientSessionCache 实现会话恢复,
// 测量使用缓存 session 时的握手开销。
// BenchmarkSessionResumption_FullHandshake 基准测试完整握手(无会话恢复)。
//
// 作为对照组,测量没有 session ticket 的完整 TLS 握手开销,
// 与 BenchmarkSessionResumption 对比评估会话恢复的性能提升。
// BenchmarkSessionTicketManager_ApplyToTLSConfig 基准测试应用 Session Ticket 到 TLS 配置的开销。
func BenchmarkSessionTicketManager_ApplyToTLSConfig(b *testing.B) {
sessionMgr, err := NewSessionTicketManager(config.SessionTicketsConfig{
@ -408,7 +405,6 @@ func BenchmarkSessionTicketManager_ApplyToTLSConfig(b *testing.B) {
//
// 测量 GetCertificate 回调在多证书场景下的查找开销。
// BenchmarkCipherSuiteParsing 基准测试加密套件解析性能。
func BenchmarkCipherSuiteParsing(b *testing.B) {
ciphers := []string{

View File

@ -271,12 +271,6 @@ func TestIsInsecureCipher(t *testing.T) {
}
}
// generateTestCert generates a self-signed certificate for testing
func generateTestCert(t *testing.T) ([]byte, []byte) {
t.Helper()
@ -504,7 +498,6 @@ func TestNewTLSManager_Errors(t *testing.T) {
// TestNewTLSManager_InvalidCipher 测试无效加密套件
// TestNewTLSManager_InsecureCipher 测试不安全加密套件
func TestNewTLSManager_InsecureCipher(t *testing.T) {
tmpDir := t.TempDir()
@ -533,28 +526,20 @@ func TestNewTLSManager_InsecureCipher(t *testing.T) {
// TestNewMultiTLSManager 测试多证书 TLS 管理器
// TestNewMultiTLSManager_EmptyConfigs 测试空配置
// TestNewMultiTLSManager_NilConfig 测试 nil 配置项
// TestGetCertificate 测试证书获取回调
// TestAddCertificate 测试添加证书
// TestAddCertificate_Error 测试添加证书错误
// TestRemoveCertificate 测试移除证书
// TestGetOCSPStatus_NoManager 测试无 OCSP 管理器时的状态
// TestParsePEMChain 测试 PEM 证书链解析
func TestParsePEMChain(t *testing.T) {
// 测试有效的 PEM 数据
@ -657,19 +642,14 @@ func TestMatchMarker(t *testing.T) {
// TestGetCertificate_NoCertificate 测试无证书时的错误情况
// TestGetConfigForClientWithOCSP 测试 OCSP 配置回调
// TestLoadCertificate_WithCertChain 测试带证书链的加载
// TestLoadCertificate_InvalidChain 测试无效证书链
// TestCreateTLSConfig_NilConfig 测试 nil 配置
// TestNewTLSManager_WithSessionTickets 测试启用 Session Tickets
func TestNewTLSManager_WithSessionTickets(t *testing.T) {
tmpDir := t.TempDir()

View File

@ -994,5 +994,3 @@ func (s *udpServer) cleanupExpiredSessions() {
}
}
}

View File

@ -215,24 +215,6 @@ func TestHandleConnection_DialFail(t *testing.T) {
}
}
// TestAcceptLoop_Error 测试 acceptLoop 错误处理路径
func TestAcceptLoop_Error(t *testing.T) {
s := NewServer()

View File

@ -195,8 +195,6 @@ func TestIPHashBalancer(t *testing.T) {
}
}
func TestUpstreamSelect(t *testing.T) {
u := &Upstream{
targets: []*Target{
@ -239,10 +237,6 @@ func TestTargetHealthy(t *testing.T) {
}
}
func TestConcurrentConnections(t *testing.T) {
s := NewServer()
@ -265,8 +259,6 @@ func TestConcurrentConnections(t *testing.T) {
}
}
func TestUDPServerInvalidUpstream(t *testing.T) {
s := NewServer()
@ -277,8 +269,6 @@ func TestUDPServerInvalidUpstream(t *testing.T) {
}
}
func TestUDPSessionKey(t *testing.T) {
addr1, _ := net.ResolveUDPAddr("udp", "127.0.0.1:1234")
addr2, _ := net.ResolveUDPAddr("udp", "127.0.0.1:5678")
@ -322,10 +312,6 @@ func TestNewUDPServer(t *testing.T) {
}
}
func TestRoundRobinBalancerWithSingleTarget(t *testing.T) {
rb := newRoundRobin()
targets := []*Target{
@ -389,8 +375,6 @@ func TestAddUpstreamWithLeastConn(t *testing.T) {
}
}
func TestUpstreamSelectNoHealthy(t *testing.T) {
u := &Upstream{
targets: []*Target{
@ -442,8 +426,6 @@ func TestCleanupExpiredSessions(t *testing.T) {
srv.mu.RUnlock()
}
func TestUDPSessionOperations(t *testing.T) {
// 创建 UDP 连接
udpAddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:0")

View File

@ -31,5 +31,3 @@ func GetInternalRedirectPath(ctx *fasthttp.RequestCtx) string {
}
return ""
}

View File

@ -166,8 +166,6 @@ func TestInternalRedirectKey(t *testing.T) {
}
}
// TestHTTPError_CustomErrors 测试自定义 HTTPError
func TestHTTPError_CustomErrors(t *testing.T) {
tests := []struct {

View File

@ -301,5 +301,3 @@ func SetResponseInfoInContext(ctx *fasthttp.RequestCtx, status int, bodySize int
ctx.SetUserValue(VarBodyBytesSent, bodySize)
ctx.SetUserValue(VarRequestTime, durationNs)
}

View File

@ -281,5 +281,3 @@ func GetSSLClientEmail(ctx *fasthttp.RequestCtx) string {
}
return ""
}

View File

@ -296,20 +296,6 @@ func TestGetSSLClientEmail(t *testing.T) {
}
}
// TestSSLVariablesInContext 测试通过 VariableContext 访问 SSL 变量
// 注意ssl_client_verify 在非 TLS 连接下会返回 NONE因为 GetSSLClientVerify 检查 ctx.IsTLS()
func TestSSLVariablesInContext(t *testing.T) {

View File

@ -548,5 +548,3 @@ func (vc *Context) Expand(template string) string {
return vc.Get(name)
}, true)
}

View File

@ -173,8 +173,6 @@ func BenchmarkVariableSetAndGet(b *testing.B) {
}
}
// BenchmarkVariableExpandLongTemplate 测试长模板展开性能。
//
// 模拟完整访问日志格式,约 200 字符。

View File

@ -282,10 +282,6 @@ func TestResponseInfoVariables(t *testing.T) {
}
}
// BenchmarkExpandSimple 基准测试:简单变量展开
func BenchmarkExpandSimple(b *testing.B) {
ctx := &fasthttp.RequestCtx{}
@ -375,8 +371,6 @@ func BenchmarkPoolGetPut(b *testing.B) {
}
}
// TestPoolReuse 测试池复用
func TestPoolReuse(t *testing.T) {
ctx := mockRequestCtx(t)
@ -399,8 +393,6 @@ func TestPoolReuse(t *testing.T) {
ReleaseContext(vc2)
}
// TestReleaseNilContext 测试释放 nil context
func TestReleaseNilContext(_ *testing.T) {
// 不应该 panic
@ -422,12 +414,6 @@ func TestGetBuiltin(t *testing.T) {
}
}
// TestEmptyTemplate 测试空模板
func TestEmptyTemplate(t *testing.T) {
ctx := mockRequestCtx(t)
@ -501,8 +487,6 @@ func TestPoolPutNil(_ *testing.T) {
ReleaseContext(nil)
}
// TestSetResponseInfo 测试 SetResponseInfo
func TestSetResponseInfo(t *testing.T) {
ctx := mockRequestCtx(t)
@ -535,16 +519,6 @@ func TestSetServerName(t *testing.T) {
}
}
// TestUpstreamVariables 测试上游变量
func TestUpstreamVariables(t *testing.T) {
ctx := mockRequestCtx(t)
@ -749,12 +723,6 @@ func BenchmarkUpstreamVariables(b *testing.B) {
}
}
// TestEphemeralGet 测试 EphemeralGet 方法
func TestEphemeralGet(t *testing.T) {
ctx := mockRequestCtx(t)