Documentation
¶
Index ¶
- func AccessTokenFromData(data json.RawMessage) (string, error)
- func IsBenchmarkRun() bool
- func IsRaceRun() bool
- func SetJSONConfigLogLevel(configPath, level string) error
- type GRPCTestIdentity
- type GRPCTestPKI
- type ProcessOptions
- type ResponseEnvelope
- type Suite
- func (s *Suite) DoJSON(method, path, token string, body interface{}) (ResponseEnvelope, error)
- func (s *Suite) DumpGoroutines(destination string) error
- func (s *Suite) KillProcess()
- func (s *Suite) PrintLog()
- func (s *Suite) ReadWebSocket(t testing.TB, connection *websocket.Conn, timeout time.Duration) WebSocketMessage
- func (s *Suite) RequestJSON(t testing.TB, method, path, token string, body interface{}) ResponseEnvelope
- func (s *Suite) Restart() error
- func (s *Suite) Stop()
- func (s *Suite) StopProcess() error
- func (s *Suite) StreamWebSocket(t testing.TB, connection *websocket.Conn) <-chan WebSocketMessage
- func (s *Suite) TokenFor(t testing.TB, userID string, tokenType int) string
- func (s *Suite) TokenPoolFor(t testing.TB, prefix string, count, tokenType int) []string
- func (s *Suite) TransportStats(t testing.TB) TransportStatsSnapshot
- func (s *Suite) WriteWebSocket(t testing.TB, connection *websocket.Conn, event, channel string, ...)
- type TokenResponse
- type TransportStatsSnapshot
- type WebSocketMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessTokenFromData ¶
func AccessTokenFromData(data json.RawMessage) (string, error)
AccessTokenFromData 优先解析结构化 Token 响应,并在过渡期兼容旧字符串响应。
func IsBenchmarkRun ¶
func IsBenchmarkRun() bool
IsBenchmarkRun 判断当前 go test 是否请求 benchmark,用于关闭子进程 race 插桩。
func SetJSONConfigLogLevel ¶
SetJSONConfigLogLevel 仅用于已由框架生成的临时集成测试配置。 benchmark 可用它关闭 info 级访问日志,避免把日志 I/O 误计为业务热路径成本。
Types ¶
type GRPCTestIdentity ¶
type GRPCTestPKI ¶
type GRPCTestPKI struct {
CAFile string
Services map[string]GRPCTestIdentity
Client GRPCTestIdentity
}
func NewGRPCTestPKI ¶
func NewGRPCTestPKI(t testing.TB, serviceNames ...string) *GRPCTestPKI
NewGRPCTestPKI creates a test-only CA and identities without shelling out to openssl. Service certificates are valid for server and client mTLS use.
type ProcessOptions ¶
type ProcessOptions struct {
// Configurations 在进程启动前写入标准 etc/{service}.json,不增加生产故障注入入口。
Configurations map[string]interface{}
BuildPackage string
BinaryName string
TempPrefix string
ServiceCount int
ServiceIndex int
// HTTPServiceOffsets 指定稀疏的实际监听偏移;空值保持原来连续端口契约。
HTTPServiceOffsets []int
GRPCServiceCount int
Arguments []string
Environment map[string]string
DisableRace bool
}
ProcessOptions 描述一个与具体业务无关的示例进程启动方式。
type ResponseEnvelope ¶
type ResponseEnvelope struct {
HTTPStatus int `json:"-"`
Body string `json:"-"`
Success bool `json:"success"`
ErrorCode int `json:"errorCode"`
ErrorMessage string `json:"errorMessage"`
Data json.RawMessage `json:"data"`
}
ResponseEnvelope 对应框架默认 HTTP 响应外壳。
type Suite ¶
type Suite struct {
RootDir string
BasePort int
GRPCBasePort int
BaseURL string
WebSocketURL string
Binary string
Arguments []string
Environment map[string]string
HTTPServiceOffsets []int
// contains filtered or unexported fields
}
Suite 保存一次集成测试进程共享的服务地址和子进程资源。
func StartProcess ¶
func StartProcess(options ProcessOptions) (*Suite, error)
StartProcess 构建并启动示例进程,只处理通用进程、端口、日志和临时目录生命周期。 服务首次启动时由框架在临时运行目录自动生成配置文件。
func (*Suite) DoJSON ¶
func (s *Suite) DoJSON(method, path, token string, body interface{}) (ResponseEnvelope, error)
DoJSON 发起真实 HTTP 请求并返回可由测试或 benchmark 自行处理的结果。
func (*Suite) DumpGoroutines ¶ added in v1.4.0
DumpGoroutines 在失败窗口中捕获当前夹具进程的go-zero SIGUSR1栈,不启用持续profile。 调用方必须在停止进程前等待本方法结束;只读取本PID新生成的诊断文件。
func (*Suite) ReadWebSocket ¶
func (s *Suite) ReadWebSocket(t testing.TB, connection *websocket.Conn, timeout time.Duration) WebSocketMessage
ReadWebSocket 在给定时限内读取并解析一条 WebSocket 消息。
func (*Suite) RequestJSON ¶
func (s *Suite) RequestJSON(t testing.TB, method, path, token string, body interface{}) ResponseEnvelope
RequestJSON 发起 HTTP 请求并解析框架默认响应外壳。
func (*Suite) StopProcess ¶
StopProcess 优雅停止子进程并返回实际退出错误;5秒未退出会强杀并明确报错。 保留配置、数据库和日志供恢复测试核验,不能把race非零退出或强杀算成成功。
func (*Suite) StreamWebSocket ¶
StreamWebSocket 持续读取指定连接,使多次“没有消息”断言不会破坏连接状态。
func (*Suite) TokenPoolFor ¶
TokenPoolFor 在 benchmark 计时前创建一组可轮转的身份令牌。 长稳流量应在固定用户池中均匀分散,避免单用户列表无界增长污染读写吞吐曲线。
func (*Suite) TransportStats ¶
func (s *Suite) TransportStats(t testing.TB) TransportStatsSnapshot
TransportStats reads the request-bound ServiceContext snapshot through the local-only server-management route. It never infers protocol use from logs.
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
TokenType string `json:"token_type"`
AccessExpiresIn int64 `json:"access_expires_in"`
RefreshExpiresIn int64 `json:"refresh_expires_in,omitempty"`
}
TokenResponse 对应框架 Callback、Refresh 和 TestToken 的结构化 Token 响应。
type TransportStatsSnapshot ¶
type TransportStatsSnapshot struct {
Transport struct {
GRPCSelected uint64
HTTPSelected uint64
SendSuccess uint64
SendFailure uint64
HTTPFallback uint64
InboundGRPC uint64
} `json:"transport"`
Fallback []string `json:"fallback"`
}
TransportStatsSnapshot is the structured local server-management response used to prove which internal transport a real integration flow selected.
type WebSocketMessage ¶
type WebSocketMessage struct {
Event string `json:"event"`
Channel string `json:"channel"`
Data json.RawMessage `json:"data"`
}
WebSocketMessage 对应框架 WebSocket 的 event/channel/data 信封。