Compare commits

..

2 Commits

Author SHA1 Message Date
hoteas 8fb6565d9f feat(api): 新增 RunSub 支持接口测试内部分场景
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-13 15:21:23 +08:00
hoteas 3ff3953dff feat(api): 新增 AtPath 方法以支持跨接口断言
- 实现 AtPath 方法,返回指向其它 API 路径的 Api 实例,增强 API 的灵活性与可用性。
2026-06-30 06:54:02 +08:00
+26
View File
@@ -61,6 +61,32 @@ func (a *Api) WithSession(s Map) *Api {
}
}
// AtPath 返回指向其它 API 路径的 Api(跨接口断言时用)
func (a *Api) AtPath(path string) *Api {
return &Api{
app: a.app,
path: path,
t: a.t,
session: a.session,
}
}
// RunSub 在单个接口测试 Func 内再分子场景,便于 go test -run 收窄。
func (a *Api) RunSub(desc string, fn func(a *Api)) {
if a == nil || a.t == nil {
fn(a)
return
}
a.t.Run(desc, func(t *testing.T) {
fn(&Api{
app: a.app,
path: a.path,
t: t,
session: a.session,
})
})
}
// JSON 设置 JSON body,返回 ApiCase 构建器
func (a *Api) JSON(body interface{}) *ApiCase {
c := a.newCase()