@@ -106,33 +106,30 @@ import (
106106 "github.com/coze-dev/coze-studio/backend/types/errno"
107107)
108108
109- var (
110- publishPatcher * mockey.Mocker
111- )
112-
113109func TestMain (m * testing.M ) {
114110 callbacks .AppendGlobalHandlers (service .GetTokenCallbackHandler ())
115111 service .RegisterAllNodeAdaptors ()
116112 os .Exit (m .Run ())
117113}
118114
119115type wfTestRunner struct {
120- t * testing.T
121- h * server.Hertz
122- ctrl * gomock.Controller
123- idGen * mock.MockIDGenerator
124- appVarS * mockvar.MockStore
125- userVarS * mockvar.MockStore
126- varGetter * mockvar.MockVariablesMetaGetter
127- modelManage * mockmodel.MockManager
128- plugin * mockPlugin.MockPluginService
129- tos * storageMock.MockStorage
130- knowledge * knowledgemock.MockKnowledge
131- database * databasemock.MockDatabase
132- pluginSrv * pluginmock.MockPluginService
133- internalModel * testutil.UTChatModel
134- ctx context.Context
135- closeFn func ()
116+ t * testing.T
117+ h * server.Hertz
118+ ctrl * gomock.Controller
119+ idGen * mock.MockIDGenerator
120+ appVarS * mockvar.MockStore
121+ userVarS * mockvar.MockStore
122+ varGetter * mockvar.MockVariablesMetaGetter
123+ modelManage * mockmodel.MockManager
124+ plugin * mockPlugin.MockPluginService
125+ tos * storageMock.MockStorage
126+ knowledge * knowledgemock.MockKnowledge
127+ database * databasemock.MockDatabase
128+ pluginSrv * pluginmock.MockPluginService
129+ internalModel * testutil.UTChatModel
130+ publishPatcher * mockey.Mocker
131+ ctx context.Context
132+ closeFn func ()
136133}
137134
138135var req2URL = map [reflect.Type ]string {
@@ -256,7 +253,7 @@ func newWfTestRunner(t *testing.T) *wfTestRunner {
256253 workflowRepo := service .NewWorkflowRepository (mockIDGen , db , redisClient , mockTos , cpStore , utChatModel )
257254 mockey .Mock (appworkflow .GetWorkflowDomainSVC ).Return (service .NewWorkflowService (workflowRepo )).Build ()
258255 mockey .Mock (workflow2 .GetRepository ).Return (workflowRepo ).Build ()
259- publishPatcher = mockey .Mock (appworkflow .PublishWorkflowResource ).Return (nil ).Build ()
256+ publishPatcher : = mockey .Mock (appworkflow .PublishWorkflowResource ).Return (nil ).Build ()
260257
261258 mockCU := mockCrossUser .NewMockUser (ctrl )
262259 mockCU .EXPECT ().GetUserSpaceList (gomock .Any (), gomock .Any ()).Return ([]* crossuser.EntitySpace {
@@ -305,9 +302,7 @@ func newWfTestRunner(t *testing.T) *wfTestRunner {
305302 }, nil ).Build ()
306303
307304 f := func () {
308- if publishPatcher != nil {
309- publishPatcher .UnPatch ()
310- }
305+ publishPatcher .UnPatch ()
311306 m .UnPatch ()
312307 m1 .UnPatch ()
313308 m2 .UnPatch ()
@@ -320,22 +315,23 @@ func newWfTestRunner(t *testing.T) *wfTestRunner {
320315 }
321316
322317 return & wfTestRunner {
323- t : t ,
324- h : h ,
325- ctrl : ctrl ,
326- idGen : mockIDGen ,
327- appVarS : mockGlobalAppVarStore ,
328- userVarS : mockGlobalUserVarStore ,
329- varGetter : mockVarGetter ,
330- modelManage : mockModelManage ,
331- plugin : mPlugin ,
332- tos : mockTos ,
333- knowledge : mockKwOperator ,
334- database : mockDatabaseOperator ,
335- internalModel : utChatModel ,
336- ctx : context .Background (),
337- closeFn : f ,
338- pluginSrv : mockPluginSrv ,
318+ t : t ,
319+ h : h ,
320+ ctrl : ctrl ,
321+ idGen : mockIDGen ,
322+ appVarS : mockGlobalAppVarStore ,
323+ userVarS : mockGlobalUserVarStore ,
324+ varGetter : mockVarGetter ,
325+ modelManage : mockModelManage ,
326+ plugin : mPlugin ,
327+ tos : mockTos ,
328+ knowledge : mockKwOperator ,
329+ database : mockDatabaseOperator ,
330+ internalModel : utChatModel ,
331+ ctx : context .Background (),
332+ closeFn : f ,
333+ pluginSrv : mockPluginSrv ,
334+ publishPatcher : publishPatcher ,
339335 }
340336}
341337
@@ -4147,14 +4143,7 @@ func TestCopyWorkflowAppToLibrary(t *testing.T) {
41474143
41484144 }
41494145
4150- if publishPatcher != nil {
4151- publishPatcher .UnPatch ()
4152- }
4153- localPatcher := mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ()
4154- defer func () {
4155- localPatcher .UnPatch ()
4156- publishPatcher = mockey .Mock (appworkflow .PublishWorkflowResource ).Return (nil ).Build ()
4157- }()
4146+ defer mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ().UnPatch ()
41584147
41594148 appID := "7513788954458456064"
41604149 appIDInt64 , _ := strconv .ParseInt (appID , 10 , 64 )
@@ -4265,14 +4254,8 @@ func TestCopyWorkflowAppToLibrary(t *testing.T) {
42654254 return nil
42664255
42674256 }
4268- if publishPatcher != nil {
4269- publishPatcher .UnPatch ()
4270- }
4271- localPatcher := mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ()
4272- defer func () {
4273- localPatcher .UnPatch ()
4274- publishPatcher = mockey .Mock (appworkflow .PublishWorkflowResource ).Return (nil ).Build ()
4275- }()
4257+
4258+ defer mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ().UnPatch ()
42764259
42774260 defer mockey .Mock ((* appknowledge .KnowledgeApplicationService ).CopyKnowledge ).Return (& modelknowledge.CopyKnowledgeResponse {
42784261 TargetKnowledgeID : 100100 ,
@@ -4313,6 +4296,7 @@ func TestCopyWorkflowAppToLibrary(t *testing.T) {
43134296func TestMoveWorkflowAppToLibrary (t * testing.T ) {
43144297 mockey .PatchConvey ("test move workflow" , t , func () {
43154298 r := newWfTestRunner (t )
4299+ r .publishPatcher .UnPatch ()
43164300 defer r .closeFn ()
43174301 vars := map [string ]* vo.TypeInfo {
43184302 "app_v1" : {
@@ -4354,14 +4338,7 @@ func TestMoveWorkflowAppToLibrary(t *testing.T) {
43544338
43554339 }
43564340
4357- if publishPatcher != nil {
4358- publishPatcher .UnPatch ()
4359- }
4360- localPatcher := mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ()
4361- defer func () {
4362- localPatcher .UnPatch ()
4363- publishPatcher = mockey .Mock (appworkflow .PublishWorkflowResource ).Return (nil ).Build ()
4364- }()
4341+ defer mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ().UnPatch ()
43654342
43664343 defer mockey .Mock ((* appknowledge .KnowledgeApplicationService ).MoveKnowledgeToLibrary ).Return (nil ).Build ().UnPatch ()
43674344 defer mockey .Mock ((* appmemory .DatabaseApplicationService ).MoveDatabaseToLibrary ).Return (& appmemory.MoveDatabaseToLibraryResponse {}, nil ).Build ().UnPatch ()
@@ -4479,6 +4456,7 @@ func TestMoveWorkflowAppToLibrary(t *testing.T) {
44794456func TestDuplicateWorkflowsByAppID (t * testing.T ) {
44804457 mockey .PatchConvey ("test duplicate work" , t , func () {
44814458 r := newWfTestRunner (t )
4459+ r .publishPatcher .UnPatch ()
44824460 defer r .closeFn ()
44834461
44844462 vars := map [string ]* vo.TypeInfo {
@@ -4516,14 +4494,7 @@ func TestDuplicateWorkflowsByAppID(t *testing.T) {
45164494
45174495 }
45184496
4519- if publishPatcher != nil {
4520- publishPatcher .UnPatch ()
4521- }
4522- localPatcher := mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ()
4523- defer func () {
4524- localPatcher .UnPatch ()
4525- publishPatcher = mockey .Mock (appworkflow .PublishWorkflowResource ).Return (nil ).Build ()
4526- }()
4497+ defer mockey .Mock (appworkflow .PublishWorkflowResource ).To (mockPublishWorkflowResource ).Build ().UnPatch ()
45274498
45284499 appIDInt64 := int64 (7513788954458456064 )
45294500
0 commit comments