feat(testing): Listener 链式入口并精简测试文档运行指引
将 connect listener 并入 Test 链、删除 NewTestApp,正文只示范 -run 单测,全量命令仅保留在文末 CI 节。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+14
-7
@@ -41,10 +41,9 @@ type TestApp struct {
|
||||
}
|
||||
|
||||
// Test 创建测试应用(链式入口,延迟 Init 以便先 WorkDir)
|
||||
func Test(configPath string, listeners ...func(*Context) bool) *TestApp {
|
||||
func Test(configPath string) *TestApp {
|
||||
return &TestApp{
|
||||
configPath: configPath,
|
||||
listeners: listeners,
|
||||
collector: &TestCollector{},
|
||||
}
|
||||
}
|
||||
@@ -55,6 +54,19 @@ func (that *TestApp) WorkDir(dir string) *TestApp {
|
||||
return that
|
||||
}
|
||||
|
||||
// Listener 追加连接监听(可选;可多次调用或一次传多个)。
|
||||
// Init 前仅暂存,ensureInit 时批量 SetConnectListener;Init 后立刻挂上。
|
||||
// 返回 true 表示已处理并停止进入控制器,false 继续。
|
||||
func (that *TestApp) Listener(fns ...func(*Context) bool) *TestApp {
|
||||
that.listeners = append(that.listeners, fns...)
|
||||
if that.inited && that.Application != nil {
|
||||
for _, fn := range fns {
|
||||
that.SetConnectListener(fn)
|
||||
}
|
||||
}
|
||||
return that
|
||||
}
|
||||
|
||||
// Swagger 启用接口级增量 Swagger 写入。
|
||||
// 参数可选:Swagger() / Swagger(title) / Swagger(title, version) / Swagger(title, version, outputDir)
|
||||
func (that *TestApp) Swagger(args ...string) *TestApp {
|
||||
@@ -285,11 +297,6 @@ func (c *TestCollector) MarkFlowVisited(name string) {
|
||||
c.VisitedFlows[name] = true
|
||||
}
|
||||
|
||||
// NewTestApp 立即 Init 的便捷构造(内部委托 Test().Proj())
|
||||
func NewTestApp(configPath string, projects TestProj, listeners ...func(*Context) bool) *TestApp {
|
||||
return Test(configPath, listeners...).Proj(projects)
|
||||
}
|
||||
|
||||
// SetupForTest 初始化路由(复用 Run 的路由注册逻辑,但不启动 HTTP 服务)
|
||||
func (that *Application) SetupForTest(router Router) {
|
||||
if that.Router == nil {
|
||||
|
||||
Reference in New Issue
Block a user