@@ -67,15 +67,10 @@ func (suite *AttachFunctionTestSuite) setupAttachFunctionMocks(ctx context.Conte
6767 databaseName := request .Database
6868 functionName := request .FunctionName
6969
70- // Phase 0: No existing attached function
71- suite .mockMetaDomain .On ("AttachedFunctionDb" , ctx ).Return (suite .mockAttachedFunctionDb ).Once ()
72- suite .mockAttachedFunctionDb .On ("GetByName" , inputCollectionID , attachedFunctionName ).
73- Return (nil , nil ).Once ()
74-
7570 // Phase 1: Create attached function in transaction
7671 suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
77- suite .mockAttachedFunctionDb .On ("GetByName " , inputCollectionID , attachedFunctionName ).
78- Return (nil , nil ).Once ()
72+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
73+ Return ([] * dbmodel. AttachedFunction {} , nil ).Once ()
7974
8075 suite .mockMetaDomain .On ("DatabaseDb" , mock .Anything ).Return (suite .mockDatabaseDb ).Once ()
8176 suite .mockDatabaseDb .On ("GetDatabases" , tenantID , databaseName ).
@@ -172,8 +167,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_SuccessfulCreation() {
172167 // Setup mocks that will be called within the transaction (using mock.Anything for context)
173168 // Check if attached function exists (idempotency check inside transaction)
174169 suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
175- suite .mockAttachedFunctionDb .On ("GetByName " , inputCollectionID , attachedFunctionName ).
176- Return (nil , nil ).Once ()
170+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , true ).
171+ Return ([] * dbmodel. AttachedFunction {} , nil ).Once ()
177172
178173 // Look up database
179174 suite .mockMetaDomain .On ("DatabaseDb" , mock .Anything ).Return (suite .mockDatabaseDb ).Once ()
@@ -290,8 +285,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Alrea
290285
291286 // ===== Phase 1: Transaction checks if attached function exists =====
292287 suite .mockMetaDomain .On ("AttachedFunctionDb" , ctx ).Return (suite .mockAttachedFunctionDb ).Once ()
293- suite .mockAttachedFunctionDb .On ("GetByName " , inputCollectionID , attachedFunctionName ).
294- Return (existingAttachedFunction , nil ).Once ()
288+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
289+ Return ([] * dbmodel. AttachedFunction { existingAttachedFunction } , nil ).Once ()
295290
296291 // Mock transaction call
297292 suite .mockTxImpl .On ("Transaction" , ctx , mock .AnythingOfType ("func(context.Context) error" )).
@@ -375,8 +370,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_RecoveryFlow() {
375370
376371 // Phase 1: Create attached function in transaction
377372 suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
378- suite .mockAttachedFunctionDb .On ("GetByName " , inputCollectionID , attachedFunctionName ).
379- Return (nil , nil ).Once ()
373+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
374+ Return ([] * dbmodel. AttachedFunction {} , nil ).Once ()
380375
381376 suite .mockMetaDomain .On ("DatabaseDb" , mock .Anything ).Return (suite .mockDatabaseDb ).Once ()
382377 suite .mockDatabaseDb .On ("GetDatabases" , tenantID , databaseName ).
@@ -428,10 +423,10 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_RecoveryFlow() {
428423
429424 // ========== SECOND ATTEMPT: Recovery Succeeds ==========
430425
431- // Phase 0: GetByName returns incomplete attached function (with ErrAttachedFunctionNotReady, which AttachFunction handles )
426+ // Phase 0: GetAttachedFunctions returns incomplete attached function (with onlyReady=false to include all )
432427 suite .mockMetaDomain .On ("AttachedFunctionDb" , ctx ).Return (suite .mockAttachedFunctionDb ).Once ()
433- suite .mockAttachedFunctionDb .On ("GetByName " , inputCollectionID , attachedFunctionName ).
434- Return (incompleteAttachedFunction , nil ).Once ()
428+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
429+ Return ([] * dbmodel. AttachedFunction { incompleteAttachedFunction } , nil ).Once ()
435430
436431 // Validate function matches
437432 suite .mockMetaDomain .On ("FunctionDb" , ctx ).Return (suite .mockFunctionDb ).Once ()
@@ -518,8 +513,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Param
518513
519514 // ===== Phase 1: Transaction checks if task exists - finds task with different params =====
520515 suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
521- suite .mockAttachedFunctionDb .On ("GetByName " , inputCollectionID , attachedFunctionName ).
522- Return (existingAttachedFunction , nil ).Once ()
516+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , true ).
517+ Return ([] * dbmodel. AttachedFunction { existingAttachedFunction } , nil ).Once ()
523518
524519 // Validate function - returns DIFFERENT function name
525520 suite .mockMetaDomain .On ("FunctionDb" , mock .Anything ).Return (suite .mockFunctionDb ).Once ()
0 commit comments