testkit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package testkit 是 bun 栈的进程内全链测试夹具(ADR-0009 D13 蓝图桶⑦, fleetly apitest 蓝本):一组 InstalledModule 在隔离测试库(真 PG 门控) 上装配——Deps 组装(CapturePublisher/内存 bus/viper Config)→ compose.AssembleAll → policy 集 → chain.DefaultChain → grpcapiserver.New(fail-closed 校验全继承)→ GRPCServer()/HTTPHandler() 逃生口经 bufconn/httptest 无端口起服。测试拿到真实 gRPC ClientConn 与 REST base URL,走 register→login→业务 的真实链路。

定位于 contrib/bunx(偏向装配层的测试面):依赖真 PG 与 bun 适配, root 核心不反向引用。模块作者用它写跨层测试,应用作者用它替代 docker+curl 冒烟的可回归形态。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eventually

func Eventually(t testing.TB, timeout time.Duration, check func() error)

Eventually 轮询等待检查通过(50ms 间隔;torchwood 同款——内存总线 异步投递等场景的确定性等待,替代固定 sleep)。

Types

type Harness

type Harness struct {
	// Conn 是已拨号的 gRPC 客户端(bufconn,无端口)。
	Conn *grpc.ClientConn
	// HTTPURL 是 REST 面 base URL(Options.Gateway 时有效)。
	HTTPURL string
	// DB 是隔离测试库(t.Cleanup 整库 FORCE DROP)。
	DB *bun.DB
	// Deps 是装配用的共享依赖(Events=Capture 可断言)。
	Deps appkit.Deps
	// Events 是事件捕获器(发布断言用)。
	Events *testutil.CapturePublisher
	// Bus 是内存事件总线(订阅侧)。
	Bus eventbus.Bus
}

Harness 是进程内全链夹具。字段均为测试可注入/可断言面。

func New

func New(t testing.TB, opts Options) *Harness

New 装配并起服。PG 门控同 testutil 约定:无 APPKIT_TEST_PG_DSN 时整测跳过。

type Options

type Options struct {
	// Installed 参与装配的已装模块(迁移链与策略集由此派生)。
	Installed []appkit.InstalledModule
	// Config 是配置面(viper 键值;模块配置段如 identity.secret 在此给值)。
	Config map[string]any
	// Logger 测试日志;默认丢弃(slog.DiscardHandler 的等价物)。
	Logger *slog.Logger
	// ExtraStages 是应用级拦截 Stage(idem/ratelimit 等),追加进
	// DefaultChain(模块贡献 Stage 之后)。
	ExtraStages []grpcapiinterceptor.Stage
	// Gateway 启用 REST 面(httptest 无端口;HTTPURL 生效)。
	Gateway bool
}

Options 是 Harness 配置。

Jump to

Keyboard shortcuts

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