From c2a59e19c93e650fe4c5e401ccbed24dfd5626ce Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Mon, 13 Jul 2026 15:21:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E6=96=B0=E5=A2=9E=20RunSub=20?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E5=86=85?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=9C=BA=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- testing_api.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/testing_api.go b/testing_api.go index 13093c1..52554f3 100644 --- a/testing_api.go +++ b/testing_api.go @@ -71,6 +71,22 @@ func (a *Api) AtPath(path string) *Api { } } +// 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()