integration

package
v1.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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 IsRaceRun

func IsRaceRun() bool

IsRaceRun 判断当前测试二进制是否由 go test -race 构建。

func SetJSONConfigLogLevel

func SetJSONConfigLogLevel(configPath, level string) error

SetJSONConfigLogLevel 仅用于已由框架生成的临时集成测试配置。 benchmark 可用它关闭 info 级访问日志,避免把日志 I/O 误计为业务热路径成本。

Types

type GRPCTestIdentity

type GRPCTestIdentity struct {
	CertFile   string
	KeyFile    string
	ServerName string
}

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

func (s *Suite) DumpGoroutines(destination string) error

DumpGoroutines 在失败窗口中捕获当前夹具进程的go-zero SIGUSR1栈,不启用持续profile。 调用方必须在停止进程前等待本方法结束;只读取本PID新生成的诊断文件。

func (*Suite) KillProcess

func (s *Suite) KillProcess()

KillProcess 强制终止子进程但保留运行目录,用于验证崩溃恢复。

func (*Suite) PrintLog

func (s *Suite) PrintLog()

PrintLog 在测试失败时输出子进程日志。

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) Restart

func (s *Suite) Restart() error

Restart 使用同一二进制、端口和运行目录重新启动服务。

func (*Suite) Stop

func (s *Suite) Stop()

Stop 先请求优雅退出,超时后强制结束子进程并清理临时文件。

func (*Suite) StopProcess

func (s *Suite) StopProcess() error

StopProcess 优雅停止子进程并返回实际退出错误;5秒未退出会强杀并明确报错。 保留配置、数据库和日志供恢复测试核验,不能把race非零退出或强杀算成成功。

func (*Suite) StreamWebSocket

func (s *Suite) StreamWebSocket(t testing.TB, connection *websocket.Conn) <-chan WebSocketMessage

StreamWebSocket 持续读取指定连接,使多次“没有消息”断言不会破坏连接状态。

func (*Suite) TokenFor

func (s *Suite) TokenFor(t testing.TB, userID string, tokenType int) string

TokenFor 通过框架内建 TestToken 路由获取指定用户类型的令牌。

func (*Suite) TokenPoolFor

func (s *Suite) TokenPoolFor(t testing.TB, prefix string, count, tokenType int) []string

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.

func (*Suite) WriteWebSocket

func (s *Suite) WriteWebSocket(t testing.TB, connection *websocket.Conn, event, channel string, data interface{})

WriteWebSocket 发送符合框架协议的 WebSocket 消息。

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 信封。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL