@@ -18,15 +18,6 @@ import (
1818 "google.golang.org/protobuf/types/known/timestamppb"
1919)
2020
21- // testMinimalUUIDv7 is the test's copy of minimalUUIDv7 from task.go
22- // UUIDv7 format: [timestamp (48 bits)][version (4 bits)][random (12 bits)][variant (2 bits)][random (62 bits)]
23- // This UUID has all zeros for timestamp and random bits, making it the minimal valid UUIDv7.
24- var testMinimalUUIDv7 = uuid.UUID {
25- 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // timestamp = 0 (bytes 0-5)
26- 0x70 , 0x00 , // version 7 (0x7) in high nibble, low nibble = 0 (bytes 6-7)
27- 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , // variant bits + rest = 0 (bytes 8-15)
28- }
29-
3021// MockMemberlistStore is a mock implementation of memberlist_manager.IMemberlistStore for testing
3122type MockMemberlistStore struct {
3223 mock.Mock
@@ -57,50 +48,6 @@ type AttachFunctionTestSuite struct {
5748 coordinator * Coordinator
5849}
5950
60- // setupAttachFunctionMocks sets up all the mocks for an AttachFunction call (Phases 0 and 1)
61- // Returns a function that can be called to capture the created attached function ID
62- func (suite * AttachFunctionTestSuite ) setupAttachFunctionMocks (ctx context.Context , request * coordinatorpb.AttachFunctionRequest , databaseID string , functionID uuid.UUID ) func (* dbmodel.AttachedFunction ) bool {
63- inputCollectionID := request .InputCollectionId
64- attachedFunctionName := request .Name
65- outputCollectionName := request .OutputCollectionName
66- tenantID := request .TenantId
67- databaseName := request .Database
68- functionName := request .FunctionName
69-
70- // Phase 0: No existing attached function
71- suite .mockMetaDomain .On ("AttachedFunctionDb" , ctx ).Return (suite .mockAttachedFunctionDb ).Once ()
72- suite .mockAttachedFunctionDb .On ("GetAnyByName" , inputCollectionID , attachedFunctionName ).
73- Return (nil , nil ).Once ()
74-
75- // Phase 1: Create attached function in transaction
76- suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
77- suite .mockAttachedFunctionDb .On ("GetAnyByName" , inputCollectionID , attachedFunctionName ).
78- Return (nil , nil ).Once ()
79-
80- suite .mockMetaDomain .On ("DatabaseDb" , mock .Anything ).Return (suite .mockDatabaseDb ).Once ()
81- suite .mockDatabaseDb .On ("GetDatabases" , tenantID , databaseName ).
82- Return ([]* dbmodel.Database {{ID : databaseID , Name : databaseName }}, nil ).Once ()
83-
84- suite .mockMetaDomain .On ("FunctionDb" , mock .Anything ).Return (suite .mockFunctionDb ).Once ()
85- suite .mockFunctionDb .On ("GetByName" , functionName ).
86- Return (& dbmodel.Function {ID : functionID , Name : functionName }, nil ).Once ()
87-
88- suite .mockMetaDomain .On ("CollectionDb" , mock .Anything ).Return (suite .mockCollectionDb ).Once ()
89- suite .mockCollectionDb .On ("GetCollections" ,
90- []string {inputCollectionID }, (* string )(nil ), tenantID , databaseName , (* int32 )(nil ), (* int32 )(nil ), false ).
91- Return ([]* dbmodel.CollectionAndMetadata {{Collection : & dbmodel.Collection {ID : inputCollectionID }}}, nil ).Once ()
92-
93- suite .mockMetaDomain .On ("CollectionDb" , mock .Anything ).Return (suite .mockCollectionDb ).Once ()
94- suite .mockCollectionDb .On ("GetCollections" ,
95- []string (nil ), & outputCollectionName , tenantID , databaseName , (* int32 )(nil ), (* int32 )(nil ), false ).
96- Return ([]* dbmodel.CollectionAndMetadata {}, nil ).Once ()
97-
98- // Return a matcher function that can be used to capture attached function data
99- return func (attachedFunction * dbmodel.AttachedFunction ) bool {
100- return true
101- }
102- }
103-
10451func (suite * AttachFunctionTestSuite ) SetupTest () {
10552 // Create all mocks - note: we manually control AssertExpectations
10653 // to avoid conflicts with automatic cleanup
@@ -172,8 +119,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_SuccessfulCreation() {
172119 // Setup mocks that will be called within the transaction (using mock.Anything for context)
173120 // Check if attached function exists (idempotency check inside transaction)
174121 suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
175- suite .mockAttachedFunctionDb .On ("GetAnyByName " , inputCollectionID , attachedFunctionName ).
176- Return (nil , nil ).Once ()
122+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
123+ Return ([] * dbmodel. AttachedFunction {} , nil ).Once ()
177124
178125 // Look up database
179126 suite .mockMetaDomain .On ("DatabaseDb" , mock .Anything ).Return (suite .mockDatabaseDb ).Once ()
@@ -290,8 +237,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Alrea
290237
291238 // ===== Phase 1: Transaction checks if attached function exists =====
292239 suite .mockMetaDomain .On ("AttachedFunctionDb" , ctx ).Return (suite .mockAttachedFunctionDb ).Once ()
293- suite .mockAttachedFunctionDb .On ("GetAnyByName " , inputCollectionID , attachedFunctionName ).
294- Return (existingAttachedFunction , nil ).Once ()
240+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
241+ Return ([] * dbmodel. AttachedFunction { existingAttachedFunction } , nil ).Once ()
295242
296243 // Mock transaction call
297244 suite .mockTxImpl .On ("Transaction" , ctx , mock .AnythingOfType ("func(context.Context) error" )).
@@ -375,8 +322,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_RecoveryFlow() {
375322
376323 // Phase 1: Create attached function in transaction
377324 suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
378- suite .mockAttachedFunctionDb .On ("GetAnyByName " , inputCollectionID , attachedFunctionName ).
379- Return (nil , nil ).Once ()
325+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
326+ Return ([] * dbmodel. AttachedFunction {} , nil ).Once ()
380327
381328 suite .mockMetaDomain .On ("DatabaseDb" , mock .Anything ).Return (suite .mockDatabaseDb ).Once ()
382329 suite .mockDatabaseDb .On ("GetDatabases" , tenantID , databaseName ).
@@ -428,10 +375,10 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_RecoveryFlow() {
428375
429376 // ========== SECOND ATTEMPT: Recovery Succeeds ==========
430377
431- // Phase 0: GetByName returns incomplete attached function (with ErrAttachedFunctionNotReady, which AttachFunction handles )
378+ // Phase 0: GetAttachedFunctions returns incomplete attached function (with onlyReady=false to include all )
432379 suite .mockMetaDomain .On ("AttachedFunctionDb" , ctx ).Return (suite .mockAttachedFunctionDb ).Once ()
433- suite .mockAttachedFunctionDb .On ("GetAnyByName " , inputCollectionID , attachedFunctionName ).
434- Return (incompleteAttachedFunction , nil ).Once ()
380+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
381+ Return ([] * dbmodel. AttachedFunction { incompleteAttachedFunction } , nil ).Once ()
435382
436383 // Validate function matches
437384 suite .mockMetaDomain .On ("FunctionDb" , ctx ).Return (suite .mockFunctionDb ).Once ()
@@ -518,8 +465,8 @@ func (suite *AttachFunctionTestSuite) TestAttachFunction_IdempotentRequest_Param
518465
519466 // ===== Phase 1: Transaction checks if task exists - finds task with different params =====
520467 suite .mockMetaDomain .On ("AttachedFunctionDb" , mock .Anything ).Return (suite .mockAttachedFunctionDb ).Once ()
521- suite .mockAttachedFunctionDb .On ("GetAnyByName " , inputCollectionID , attachedFunctionName ).
522- Return (existingAttachedFunction , nil ).Once ()
468+ suite .mockAttachedFunctionDb .On ("GetAttachedFunctions " , ( * uuid . UUID )( nil ), & attachedFunctionName , & inputCollectionID , false ).
469+ Return ([] * dbmodel. AttachedFunction { existingAttachedFunction } , nil ).Once ()
523470
524471 // Validate function - returns DIFFERENT function name
525472 suite .mockMetaDomain .On ("FunctionDb" , mock .Anything ).Return (suite .mockFunctionDb ).Once ()
0 commit comments