@@ -147,9 +147,7 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_SuccessfulCreation() {
147147 MinRecordsForInvocation := uint64 (100 )
148148
149149 params := & structpb.Struct {
150- Fields : map [string ]* structpb.Value {
151- "param1" : structpb .NewStringValue ("value1" ),
152- },
150+ Fields : map [string ]* structpb.Value {},
153151 }
154152
155153 request := & coordinatorpb.AttachFunctionRequest {
@@ -241,7 +239,7 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Alrea
241239 tenantID := "test-tenant"
242240 databaseName := "test-database"
243241 databaseID := "database-uuid"
244- functionID := uuid . New ()
242+ functionID := dbmodel . FunctionRecordCounter
245243 MinRecordsForInvocation := uint64 (100 )
246244
247245 params := & structpb.Struct {
@@ -288,10 +286,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Alrea
288286 suite .mockAttachedFunctionDb .On ("GetByCollectionID" , inputCollectionID ).
289287 Return ([]* dbmodel.AttachedFunction {existingAttachedFunction }, nil ).Once ()
290288
291- // Validate function by ID
292- suite .mockMetaDomain .On ("FunctionDb" , txCtx ).Return (suite .mockFunctionDb ).Once ()
293- suite .mockFunctionDb .On ("GetByID" , functionID ).
294- Return (& dbmodel.Function {ID : functionID , Name : functionName }, nil ).Once ()
289+ // Note: validateAttachedFunctionMatchesRequest uses dbmodel.GetFunctionNameByID (static lookup),
290+ // not FunctionDb.GetByID, so no mock needed for FunctionDb here
295291
296292 // Validate database matches
297293 suite .mockMetaDomain .On ("DatabaseDb" , txCtx ).Return (suite .mockDatabaseDb ).Once ()
@@ -317,7 +313,6 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Alrea
317313 // Verify all read mocks were called
318314 suite .mockMetaDomain .AssertExpectations (suite .T ())
319315 suite .mockAttachedFunctionDb .AssertExpectations (suite .T ())
320- suite .mockFunctionDb .AssertExpectations (suite .T ())
321316 suite .mockDatabaseDb .AssertExpectations (suite .T ())
322317}
323318
@@ -339,16 +334,10 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_RecoveryFlow() {
339334 tenantID := "test-tenant"
340335 databaseName := "test-database"
341336 databaseID := "database-uuid"
342- functionID := uuid . New ()
337+ functionID := dbmodel . FunctionRecordCounter
343338 MinRecordsForInvocation := uint64 (100 )
344339 now := time .Now ()
345340
346- params := & structpb.Struct {
347- Fields : map [string ]* structpb.Value {
348- "param1" : structpb .NewStringValue ("value1" ),
349- },
350- }
351-
352341 request := & coordinatorpb.AttachFunctionRequest {
353342 Name : attachedFunctionName ,
354343 InputCollectionId : inputCollectionID ,
@@ -357,7 +346,6 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_RecoveryFlow() {
357346 TenantId : tenantID ,
358347 Database : databaseName ,
359348 MinRecordsForInvocation : MinRecordsForInvocation ,
360- Params : params ,
361349 }
362350
363351 // ========== FIRST ATTEMPT: Heap Push Fails ==========
@@ -423,10 +411,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_RecoveryFlow() {
423411 suite .mockAttachedFunctionDb .On ("GetByCollectionID" , inputCollectionID ).
424412 Return ([]* dbmodel.AttachedFunction {incompleteAttachedFunction }, nil ).Once ()
425413
426- // Validate function matches
427- suite .mockMetaDomain .On ("FunctionDb" , txCtx ).Return (suite .mockFunctionDb ).Once ()
428- suite .mockFunctionDb .On ("GetByID" , functionID ).
429- Return (& dbmodel.Function {ID : functionID , Name : functionName }, nil ).Once ()
414+ // Note: validateAttachedFunctionMatchesRequest uses dbmodel.GetFunctionNameByID (static lookup),
415+ // not FunctionDb.GetByID, so no mock needed for FunctionDb here
430416
431417 // Validate database matches
432418 suite .mockMetaDomain .On ("DatabaseDb" , txCtx ).Return (suite .mockDatabaseDb ).Once ()
@@ -467,7 +453,7 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Param
467453 tenantID := "test-tenant"
468454 databaseName := "test-database"
469455 databaseID := "database-uuid"
470- existingOperatorID := uuid . New ()
456+ existingOperatorID := dbmodel . FunctionRecordCounter
471457 MinRecordsForInvocation := uint64 (100 )
472458 now := time .Now ()
473459
@@ -514,31 +500,22 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Param
514500 suite .mockAttachedFunctionDb .On ("GetByCollectionID" , inputCollectionID ).
515501 Return ([]* dbmodel.AttachedFunction {existingAttachedFunction }, nil ).Once ()
516502
517- // Validate function - returns DIFFERENT function name
518- suite .mockMetaDomain .On ("FunctionDb" , txCtx ).Return (suite .mockFunctionDb ).Once ()
519- suite .mockFunctionDb .On ("GetByID" , existingOperatorID ).
520- Return (& dbmodel.Function {
521- ID : existingOperatorID ,
522- Name : existingOperatorName , // Different from request
523- }, nil ).Once ()
524-
525- // Database lookup happens before the error is returned
526- suite .mockMetaDomain .On ("DatabaseDb" , txCtx ).Return (suite .mockDatabaseDb ).Once ()
527- suite .mockDatabaseDb .On ("GetDatabases" , tenantID , databaseName ).
528- Return ([]* dbmodel.Database {{ID : databaseID , Name : databaseName }}, nil ).Once ()
503+ // Note: validateAttachedFunctionMatchesRequest uses dbmodel.GetFunctionNameByID (static lookup)
504+ // which returns "record_counter" for FunctionRecordCounter - different from requestedOperatorName
505+ // Validation returns (false, nil) early, so DatabaseDb.GetDatabases is NOT called
529506
530507 _ = txFunc (txCtx )
531- }).Return (status .Errorf (codes .AlreadyExists , "different function is attached with this name: existing =%s, requested =%s" , existingOperatorName , requestedOperatorName )).Once ()
508+ }).Return (status .Errorf (codes .AlreadyExists , "collection already has an attached function: name=%s, function =%s, output_collection =%s" , attachedFunctionName , existingOperatorName , outputCollectionName )).Once ()
532509
533510 // Execute AttachFunction
534511 response , err := suite .coordinator .AttachFunction (ctx , request )
535512
536513 // Assertions - should fail with AlreadyExists error
537514 suite .Error (err )
538515 suite .Nil (response )
539- suite .Contains (err .Error (), "different function is attached with this name " )
516+ suite .Contains (err .Error (), "collection already has an attached function " )
540517 suite .Contains (err .Error (), existingOperatorName )
541- suite .Contains (err .Error (), requestedOperatorName )
518+ suite .Contains (err .Error (), outputCollectionName )
542519
543520 // Verify no writes occurred (Transaction IS called but Insert/Push are not)
544521 suite .mockTxImpl .AssertNumberOfCalls (suite .T (), "Transaction" , 1 )
@@ -547,7 +524,6 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Param
547524 // Verify read mocks were called
548525 suite .mockMetaDomain .AssertExpectations (suite .T ())
549526 suite .mockAttachedFunctionDb .AssertExpectations (suite .T ())
550- suite .mockFunctionDb .AssertExpectations (suite .T ())
551527}
552528
553529func TestAttachFunctionTestSuite (t * testing.T ) {
0 commit comments