feat(testing): Flows/FromCase、增量 swagger 与 Doc-Driven 门禁
补齐多接口流程联调与控制台体验,并落地仓内 Doc-Driven+TDD 总规则与文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package hotime
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
. "code.hoteas.com/golang/hotime/db"
|
||||
)
|
||||
|
||||
// FlowTest 业务流程测试集合(流程名 → 定义)
|
||||
type FlowTest map[string]FlowDef
|
||||
|
||||
// FlowDef 单条业务流程定义
|
||||
type FlowDef struct {
|
||||
Group string // 左侧分组,如 "user" / "expect_demo"
|
||||
Desc string // 流程短标题(右侧标题)
|
||||
Prep string // 业务说明与前置/数据准备(右侧描述)
|
||||
Func func(f *Flow)
|
||||
}
|
||||
|
||||
// Flow 业务流程测试入口,整条流程共用一次测试事务
|
||||
type Flow struct {
|
||||
app *TestApp
|
||||
t *testing.T
|
||||
name string
|
||||
group string
|
||||
desc string
|
||||
prep string
|
||||
session Map
|
||||
stepIdx int
|
||||
lastResp *ApiResponse
|
||||
}
|
||||
|
||||
// WithSession 返回携带 session 的 Flow
|
||||
func (f *Flow) WithSession(s Map) *Flow {
|
||||
return &Flow{
|
||||
app: f.app,
|
||||
t: f.t,
|
||||
name: f.name,
|
||||
group: f.group,
|
||||
desc: f.desc,
|
||||
prep: f.prep,
|
||||
session: s,
|
||||
stepIdx: f.stepIdx,
|
||||
}
|
||||
}
|
||||
|
||||
// Step 开始流程中的一步,返回指向指定路径的 Api(记录会归入 flows)
|
||||
func (f *Flow) Step(stepName, path string) *Api {
|
||||
f.stepIdx++
|
||||
return &Api{
|
||||
app: f.app,
|
||||
path: path,
|
||||
t: f.t,
|
||||
session: f.session,
|
||||
flowName: f.name,
|
||||
flowGroup: f.group,
|
||||
flowDesc: f.desc,
|
||||
flowPrep: f.prep,
|
||||
flowStep: stepName,
|
||||
flowStepIndex: f.stepIdx,
|
||||
flowParent: f,
|
||||
}
|
||||
}
|
||||
|
||||
// AtPath 在当前流程上下文中切换路径(不增加步骤序号)
|
||||
func (f *Flow) AtPath(path string) *Api {
|
||||
return &Api{
|
||||
app: f.app,
|
||||
path: path,
|
||||
t: f.t,
|
||||
session: f.session,
|
||||
flowName: f.name,
|
||||
flowGroup: f.group,
|
||||
flowDesc: f.desc,
|
||||
flowPrep: f.prep,
|
||||
flowStep: "",
|
||||
flowStepIndex: f.stepIdx,
|
||||
flowParent: f,
|
||||
}
|
||||
}
|
||||
|
||||
// DB 获取测试库(流程级事务内)
|
||||
func (f *Flow) DB() *HoTimeDB {
|
||||
return f.app.DB()
|
||||
}
|
||||
|
||||
// Resp 最近一次步骤响应
|
||||
func (f *Flow) Resp() *ApiResponse {
|
||||
return f.lastResp
|
||||
}
|
||||
|
||||
// SetLastResp 由框架在步骤执行后更新
|
||||
func (f *Flow) SetLastResp(r *ApiResponse) {
|
||||
f.lastResp = r
|
||||
}
|
||||
Reference in New Issue
Block a user