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, encodeSortKeys: defaultEncodeSortKeys,
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ import (
// 默认配置常量。 // 默认配置常量。
const ( const (
// DefaultPprofPath pprof 端点的默认路径。 // DefaultPprofPath pprof 端点的默认路径。
DefaultPprofPath = "/debug/pprof" DefaultPprofPath = "/debug/pprof"
) )
@ -40,13 +40,13 @@ type ServerMode string
// ServerMode 枚举值。 // ServerMode 枚举值。
const ( const (
// ServerModeSingle 单服务器模式 - 只运行一个服务器实例。 // ServerModeSingle 单服务器模式 - 只运行一个服务器实例。
ServerModeSingle ServerMode = "single" ServerModeSingle ServerMode = "single"
// ServerModeVHost 虚拟主机模式 - 多个服务器共享相同的监听地址。 // ServerModeVHost 虚拟主机模式 - 多个服务器共享相同的监听地址。
ServerModeVHost ServerMode = "vhost" ServerModeVHost ServerMode = "vhost"
// ServerModeMultiServer 多服务器模式 - 多个服务器监听不同的地址。 // ServerModeMultiServer 多服务器模式 - 多个服务器监听不同的地址。
ServerModeMultiServer ServerMode = "multi_server" ServerModeMultiServer ServerMode = "multi_server"
// ServerModeAuto 自动模式 - 根据配置自动推断运行模式。 // ServerModeAuto 自动模式 - 根据配置自动推断运行模式。
ServerModeAuto ServerMode = "auto" ServerModeAuto ServerMode = "auto"
) )
@ -72,17 +72,17 @@ const (
// // 处理每个服务器配置 // // 处理每个服务器配置
// } // }
type Config struct { type Config struct {
Mode ServerMode `yaml:"mode"` Mode ServerMode `yaml:"mode"`
Variables VariablesConfig `yaml:"variables"` Variables VariablesConfig `yaml:"variables"`
Logging LoggingConfig `yaml:"logging"` Logging LoggingConfig `yaml:"logging"`
Servers []ServerConfig `yaml:"servers"` Servers []ServerConfig `yaml:"servers"`
Stream []StreamConfig `yaml:"stream"` Stream []StreamConfig `yaml:"stream"`
Monitoring MonitoringConfig `yaml:"monitoring"` Monitoring MonitoringConfig `yaml:"monitoring"`
HTTP3 HTTP3Config `yaml:"http3"` HTTP3 HTTP3Config `yaml:"http3"`
Resolver ResolverConfig `yaml:"resolver"` Resolver ResolverConfig `yaml:"resolver"`
Performance PerformanceConfig `yaml:"performance"` Performance PerformanceConfig `yaml:"performance"`
Shutdown ShutdownConfig `yaml:"shutdown"` Shutdown ShutdownConfig `yaml:"shutdown"`
Include []IncludeConfig `yaml:"include"` // 配置引入,支持从其他文件引入配置片段 Include []IncludeConfig `yaml:"include"` // 配置引入,支持从其他文件引入配置片段
} }
// parseSize 解析大小字符串(支持 k, m 单位)。 // parseSize 解析大小字符串(支持 k, m 单位)。

View File

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

View File

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

View File

@ -1260,8 +1260,8 @@ func TestStaticHandler_AliasVsRoot(t *testing.T) {
wantContent: "from root", // /var/www/images/logo.png wantContent: "from root", // /var/www/images/logo.png
}, },
{ {
name: "alias 模式:请求路径替换匹配部分", name: "alias 模式:请求路径替换匹配部分",
handler: &StaticHandler{ handler: &StaticHandler{
alias: aliasDir, alias: aliasDir,
pathPrefix: "/images/", pathPrefix: "/images/",
pathPrefixLen: len("/images/"), pathPrefixLen: len("/images/"),

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -31,7 +31,6 @@ import (
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
"github.com/valyala/fasthttp/fasthttputil" "github.com/valyala/fasthttp/fasthttputil"
"rua.plus/lolly/internal/testutil"
"rua.plus/lolly/internal/cache" "rua.plus/lolly/internal/cache"
"rua.plus/lolly/internal/config" "rua.plus/lolly/internal/config"
"rua.plus/lolly/internal/handler" "rua.plus/lolly/internal/handler"
@ -43,6 +42,7 @@ import (
"rua.plus/lolly/internal/middleware/rewrite" "rua.plus/lolly/internal/middleware/rewrite"
"rua.plus/lolly/internal/middleware/security" "rua.plus/lolly/internal/middleware/security"
"rua.plus/lolly/internal/proxy" "rua.plus/lolly/internal/proxy"
"rua.plus/lolly/internal/testutil"
) )
// generateTestCert 生成自签名测试证书(服务器认证)。 // generateTestCert 生成自签名测试证书(服务器认证)。
@ -1446,8 +1446,8 @@ func BenchmarkE2EBasicAuth(b *testing.B) {
} }
warmupProxy(p, "/api/test", 5) warmupProxy(p, "/api/test", 5)
// 创建 Basic Auth 中间件(使用 bcrypt 哈希) // 创建 Basic Auth 中间件(使用 bcrypt 哈希)
bcryptPassword := "$2a$10$BOx2i1WZ6iFADhBylIiAAOe3OgG2tQ1dkhgLhJCNnm9beidTgqMq." bcryptPassword := "$2a$10$BOx2i1WZ6iFADhBylIiAAOe3OgG2tQ1dkhgLhJCNnm9beidTgqMq."
auth, err := security.NewBasicAuth(&config.AuthConfig{ auth, err := security.NewBasicAuth(&config.AuthConfig{
Type: "basic", Type: "basic",
RequireTLS: false, RequireTLS: false,

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 return table
} }

View File

@ -26,7 +26,7 @@ import (
// 日志级别常量(与 OpenResty/ngx_lua 兼容) // 日志级别常量(与 OpenResty/ngx_lua 兼容)
const ( const (
// LogStderr 标准错误日志级别。 // LogStderr 标准错误日志级别。
LogStderr = 0 LogStderr = 0
// LogEmerg 紧急日志级别。 // LogEmerg 紧急日志级别。
LogEmerg = 1 LogEmerg = 1
@ -48,7 +48,7 @@ const (
// HTTP 状态码常量 // HTTP 状态码常量
const ( const (
// HTTPContinue HTTP 100 继续状态码。 // HTTPContinue HTTP 100 继续状态码。
HTTPContinue = 100 HTTPContinue = 100
// HTTPSwitchingProtocols HTTP 101 切换协议状态码。 // HTTPSwitchingProtocols HTTP 101 切换协议状态码。
HTTPSwitchingProtocols = 101 HTTPSwitchingProtocols = 101
@ -390,5 +390,3 @@ func (api *ngxLogAPI) luaRedirect(L *glua.LState) int {
L.RaiseError("%s", "ngx.redirect: "+uri) L.RaiseError("%s", "ngx.redirect: "+uri)
return 0 return 0
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@ import "github.com/valyala/fasthttp"
// LocationType 常量定义,表示不同 location 匹配类型。 // LocationType 常量定义,表示不同 location 匹配类型。
const ( const (
// LocationTypeExact 精确匹配类型(=)。 // LocationTypeExact 精确匹配类型(=)。
LocationTypeExact = "exact" LocationTypeExact = "exact"
// LocationTypePrefix 前缀匹配类型。 // LocationTypePrefix 前缀匹配类型。
LocationTypePrefix = "prefix" LocationTypePrefix = "prefix"

View File

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

View File

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

View File

@ -96,7 +96,7 @@ const streamingThreshold = 64 * 1024 // 64KB
type Algorithm int type Algorithm int
const ( const (
// AlgorithmGzip 使用 gzip 压缩算法。 // AlgorithmGzip 使用 gzip 压缩算法。
AlgorithmGzip Algorithm = iota AlgorithmGzip Algorithm = iota
// AlgorithmBrotli 使用 brotli 压缩算法。 // AlgorithmBrotli 使用 brotli 压缩算法。
AlgorithmBrotli AlgorithmBrotli

View File

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

View File

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

View File

@ -36,7 +36,7 @@ const MaxRewriteIterations = 10
type Flag int type Flag int
const ( const (
// FlagLast 继续匹配其他规则nginx 行为:重新从第一条规则开始匹配)。 // FlagLast 继续匹配其他规则nginx 行为:重新从第一条规则开始匹配)。
// 匹配到规则后会重新从第一条规则开始遍历,用于多规则链式重写。 // 匹配到规则后会重新从第一条规则开始遍历,用于多规则链式重写。
FlagLast Flag = iota FlagLast Flag = iota
// FlagRedirect 返回 302 临时重定向。 // FlagRedirect 返回 302 临时重定向。

View File

@ -43,7 +43,7 @@ import (
type Action int type Action int
const ( const (
// ActionAllow 允许请求通过。 // ActionAllow 允许请求通过。
ActionAllow Action = iota ActionAllow Action = iota
// ActionDeny 拒绝请求(返回 403 Forbidden // ActionDeny 拒绝请求(返回 403 Forbidden
ActionDeny ActionDeny

View File

@ -47,7 +47,7 @@ import (
type HashAlgorithm int type HashAlgorithm int
const ( const (
// HashBcrypt bcrypt 哈希算法(默认,推荐)。 // HashBcrypt bcrypt 哈希算法(默认,推荐)。
HashBcrypt HashAlgorithm = iota HashBcrypt HashAlgorithm = iota
// HashArgon2id Argon2id 哈希算法(更安全,计算密集)。 // HashArgon2id Argon2id 哈希算法(更安全,计算密集)。
HashArgon2id HashArgon2id

View File

@ -102,7 +102,7 @@ func SetDefaultType(defaultType string) {
// - filePath: 文件路径 // - filePath: 文件路径
// //
// 返回值: // 返回值:
// - string: MIME 类型,未知类型返回 defaultMIME默认为 application/octet-stream // - string: MIME 类型,未知类型返回 defaultMIME默认为 application/octet-stream
func DetectContentType(filePath string) string { func DetectContentType(filePath string) string {
ext := strings.ToLower(filepath.Ext(filePath)) ext := strings.ToLower(filepath.Ext(filePath))

View File

@ -5,8 +5,6 @@
// 作者xfy // 作者xfy
package netutil package netutil
// StripPort 从 Host 头中移除端口号。 // StripPort 从 Host 头中移除端口号。
// //
// 支持 IPv4 和 IPv6 格式: // 支持 IPv4 和 IPv6 格式:
@ -44,5 +42,3 @@ func StripPort(host string) string {
return host 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) h.slowStartManager.OnTargetHealthy(target)
} }
} }

View File

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

View File

@ -673,17 +673,17 @@ func (p *Proxy) ServeHTTP(ctx *fasthttp.RequestCtx) {
} }
return return
} }
// 过期缓存,尝试后台刷新,同时返回旧数据 // 过期缓存,尝试后台刷新,同时返回旧数据
if !p.config.Cache.BackgroundUpdateDisable { if !p.config.Cache.BackgroundUpdateDisable {
entry.Updating.Store(true) entry.Updating.Store(true)
reqCopy := fasthttp.AcquireRequest() reqCopy := fasthttp.AcquireRequest()
ctx.Request.CopyTo(reqCopy) ctx.Request.CopyTo(reqCopy)
go func() { go func() {
defer entry.Updating.Store(false) defer entry.Updating.Store(false)
defer fasthttp.ReleaseRequest(reqCopy) defer fasthttp.ReleaseRequest(reqCopy)
p.backgroundRefresh(reqCopy, target, hashKey, origKey) p.backgroundRefresh(reqCopy, target, hashKey, origKey)
}() }()
} }
upstreamAddr = upstreamCache upstreamAddr = upstreamCache
upstreamStatus = entry.Status upstreamStatus = entry.Status
@ -990,5 +990,3 @@ func isWebSocketRequest(ctx *fasthttp.RequestCtx) bool {
upgrade := ctx.Request.Header.Peek("Upgrade") upgrade := ctx.Request.Header.Peek("Upgrade")
return strings.EqualFold(string(upgrade), "websocket") return strings.EqualFold(string(upgrade), "websocket")
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -596,10 +596,6 @@ func TestPurgeHandler_SendError(t *testing.T) {
} }
} }
// TestPurgeHandler_CacheKeyWithMethod 测试带方法的缓存键。 // TestPurgeHandler_CacheKeyWithMethod 测试带方法的缓存键。
func TestPurgeHandler_CacheKeyWithMethod(t *testing.T) { func TestPurgeHandler_CacheKeyWithMethod(t *testing.T) {
tests := []struct { tests := []struct {
@ -664,10 +660,6 @@ func TestPurgeHandler_checkAccess_NilContext(t *testing.T) {
}) })
} }
// TestPurgeHandler_ServeHTTP_WithAllowList 测试带白名单的请求处理。 // TestPurgeHandler_ServeHTTP_WithAllowList 测试带白名单的请求处理。
func TestPurgeHandler_ServeHTTP_WithAllowList(t *testing.T) { func TestPurgeHandler_ServeHTTP_WithAllowList(t *testing.T) {
cfg := &config.CacheAPIConfig{ cfg := &config.CacheAPIConfig{
@ -719,18 +711,6 @@ func TestPurgeHandler_checkAccess_WithAllowedIP(t *testing.T) {
}) })
} }
// TestPurgeHandler_PurgeByPath_HashConsistency 测试哈希一致性。 // TestPurgeHandler_PurgeByPath_HashConsistency 测试哈希一致性。
func TestPurgeHandler_PurgeByPath_HashConsistency(t *testing.T) { 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_GetResolver 测试获取解析器。
// TestServer_StopWithTimeout_WithListeners 测试带监听器的停止。 // TestServer_StopWithTimeout_WithListeners 测试带监听器的停止。
func TestServer_StopWithTimeout_WithListeners(t *testing.T) { func TestServer_StopWithTimeout_WithListeners(t *testing.T) {
cfg := &config.Config{ cfg := &config.Config{

View File

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

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ import (
type ClientVerifyMode int type ClientVerifyMode int
const ( const (
// VerifyOff 不验证客户端证书。 // VerifyOff 不验证客户端证书。
VerifyOff ClientVerifyMode = iota VerifyOff ClientVerifyMode = iota
// VerifyOn 强制验证客户端证书。 // VerifyOn 强制验证客户端证书。
VerifyOn VerifyOn
@ -256,5 +256,3 @@ type ClientCertInfo struct {
DNSNames []string DNSNames []string
Email []string Email []string
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -23,20 +23,20 @@ type HTTPError struct {
// Predefined common HTTP errors. // Predefined common HTTP errors.
var ( var (
// ErrNotFound 资源未找到错误。 // ErrNotFound 资源未找到错误。
ErrNotFound = HTTPError{Message: "Not Found", StatusCode: fasthttp.StatusNotFound} ErrNotFound = HTTPError{Message: "Not Found", StatusCode: fasthttp.StatusNotFound}
// ErrForbidden 禁止访问错误。 // ErrForbidden 禁止访问错误。
ErrForbidden = HTTPError{Message: "Forbidden", StatusCode: fasthttp.StatusForbidden} ErrForbidden = HTTPError{Message: "Forbidden", StatusCode: fasthttp.StatusForbidden}
// ErrUnauthorized 未授权错误。 // ErrUnauthorized 未授权错误。
ErrUnauthorized = HTTPError{Message: "Unauthorized", StatusCode: fasthttp.StatusUnauthorized} ErrUnauthorized = HTTPError{Message: "Unauthorized", StatusCode: fasthttp.StatusUnauthorized}
// ErrBadGateway 错误网关错误。 // ErrBadGateway 错误网关错误。
ErrBadGateway = HTTPError{Message: "Bad Gateway", StatusCode: fasthttp.StatusBadGateway} ErrBadGateway = HTTPError{Message: "Bad Gateway", StatusCode: fasthttp.StatusBadGateway}
// ErrGatewayTimeout 网关超时错误。 // ErrGatewayTimeout 网关超时错误。
ErrGatewayTimeout = HTTPError{Message: "Gateway Timeout", StatusCode: fasthttp.StatusGatewayTimeout} ErrGatewayTimeout = HTTPError{Message: "Gateway Timeout", StatusCode: fasthttp.StatusGatewayTimeout}
// ErrInternalError 内部服务器错误。 // ErrInternalError 内部服务器错误。
ErrInternalError = HTTPError{Message: "Internal Server Error", StatusCode: fasthttp.StatusInternalServerError} ErrInternalError = HTTPError{Message: "Internal Server Error", StatusCode: fasthttp.StatusInternalServerError}
// ErrTooManyRequests 请求过多错误。 // ErrTooManyRequests 请求过多错误。
ErrTooManyRequests = HTTPError{Message: "Too Many Requests", StatusCode: fasthttp.StatusTooManyRequests} ErrTooManyRequests = HTTPError{Message: "Too Many Requests", StatusCode: fasthttp.StatusTooManyRequests}
// ErrServiceUnavailable 服务不可用错误。 // ErrServiceUnavailable 服务不可用错误。
ErrServiceUnavailable = HTTPError{Message: "Service Unavailable", StatusCode: fasthttp.StatusServiceUnavailable} ErrServiceUnavailable = HTTPError{Message: "Service Unavailable", StatusCode: fasthttp.StatusServiceUnavailable}
) )

View File

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

View File

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

View File

@ -16,7 +16,7 @@ import (
// 内置变量常量 // 内置变量常量
const ( const (
// VarHost 请求主机名变量。 // VarHost 请求主机名变量。
VarHost = "host" VarHost = "host"
// VarRemoteAddr 客户端地址变量。 // VarRemoteAddr 客户端地址变量。
VarRemoteAddr = "remote_addr" VarRemoteAddr = "remote_addr"
@ -301,5 +301,3 @@ func SetResponseInfoInContext(ctx *fasthttp.RequestCtx, status int, bodySize int
ctx.SetUserValue(VarBodyBytesSent, bodySize) ctx.SetUserValue(VarBodyBytesSent, bodySize)
ctx.SetUserValue(VarRequestTime, durationNs) ctx.SetUserValue(VarRequestTime, durationNs)
} }

View File

@ -18,24 +18,24 @@ import (
// SSL 变量常量 // SSL 变量常量
const ( const (
// VarSSLClientVerify SSL 客户端证书验证结果变量。 // VarSSLClientVerify SSL 客户端证书验证结果变量。
VarSSLClientVerify = "ssl_client_verify" VarSSLClientVerify = "ssl_client_verify"
// VarSSLClientSerial SSL 客户端证书序列号变量。 // VarSSLClientSerial SSL 客户端证书序列号变量。
VarSSLClientSerial = "ssl_client_serial" VarSSLClientSerial = "ssl_client_serial"
// VarSSLClientSubject SSL 客户端证书主题变量。 // VarSSLClientSubject SSL 客户端证书主题变量。
VarSSLClientSubject = "ssl_client_subject" VarSSLClientSubject = "ssl_client_subject"
// VarSSLClientIssuer SSL 客户端证书颁发者变量。 // VarSSLClientIssuer SSL 客户端证书颁发者变量。
VarSSLClientIssuer = "ssl_client_issuer" VarSSLClientIssuer = "ssl_client_issuer"
// VarSSLClientFingerprint SSL 客户端证书指纹变量。 // VarSSLClientFingerprint SSL 客户端证书指纹变量。
VarSSLClientFingerprint = "ssl_client_fingerprint" VarSSLClientFingerprint = "ssl_client_fingerprint"
// VarSSLClientNotBefore SSL 客户端证书生效时间变量。 // VarSSLClientNotBefore SSL 客户端证书生效时间变量。
VarSSLClientNotBefore = "ssl_client_notbefore" VarSSLClientNotBefore = "ssl_client_notbefore"
// VarSSLClientNotAfter SSL 客户端证书过期时间变量。 // VarSSLClientNotAfter SSL 客户端证书过期时间变量。
VarSSLClientNotAfter = "ssl_client_notafter" VarSSLClientNotAfter = "ssl_client_notafter"
// VarSSLClientDNS SSL 客户端证书主题 DN 变量。 // VarSSLClientDNS SSL 客户端证书主题 DN 变量。
VarSSLClientDNS = "ssl_client_s_dn" VarSSLClientDNS = "ssl_client_s_dn"
// VarSSLClientEmail SSL 客户端证书邮箱变量。 // VarSSLClientEmail SSL 客户端证书邮箱变量。
VarSSLClientEmail = "ssl_client_email" VarSSLClientEmail = "ssl_client_email"
sslProtocolNone = "NONE" sslProtocolNone = "NONE"
) )
@ -281,5 +281,3 @@ func GetSSLClientEmail(ctx *fasthttp.RequestCtx) string {
} }
return "" return ""
} }

View File

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

View File

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

View File

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

View File

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