xfy 2458ac1ed1 docs: 为其余模块添加标准化 godoc 注释
为剩余模块添加完整文档注释:
- app: 应用生命周期管理
- cache: 文件缓存
- config: 配置加载器
- handler: 静态文件处理和错误页面
- http2/http3: HTTP/2 和 HTTP/3 适配器
- loadbalance: 负载均衡算法和均衡器
- middleware: bodylimit、compression、rewrite、security
- mimeutil: MIME 类型检测
- netutil: URL 处理工具
- resolver: DNS 解析器
- server: 服务器升级处理
- ssl: SSL/TLS 和 OCSP
- stream: 流处理
- testutil: 测试工具
- variable: 变量池和 SSL 变量

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-20 10:59:53 +08:00

42 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package testutil 提供测试辅助工具函数。
//
// 该文件包含请求上下文创建相关的辅助函数,用于单元测试:
// - 创建测试用的 fasthttp.RequestCtx
// - 支持 method、path、body、header 配置
//
// 主要用途:
//
// 简化单元测试中请求上下文的创建,避免重复代码。
//
// 注意事项:
// - 仅用于测试,不应在生产代码中使用
//
// 作者xfy
package testutil
import "github.com/valyala/fasthttp"
// NewRequestCtx 创建测试用的请求上下文
func NewRequestCtx(method, path string) *fasthttp.RequestCtx {
ctx := &fasthttp.RequestCtx{}
ctx.Request.Header.SetMethod(method)
ctx.Request.SetRequestURI(path)
return ctx
}
// NewRequestCtxWithBody 创建带 body 的测试请求上下文
func NewRequestCtxWithBody(method, path, body string) *fasthttp.RequestCtx {
ctx := NewRequestCtx(method, path)
ctx.Request.SetBodyString(body)
return ctx
}
// NewRequestCtxWithHeader 创建带 header 的测试请求上下文
func NewRequestCtxWithHeader(method, path string, headers map[string]string) *fasthttp.RequestCtx {
ctx := NewRequestCtx(method, path)
for k, v := range headers {
ctx.Request.Header.Set(k, v)
}
return ctx
}