@@ -752,30 +752,122 @@ func TestSubmitBulkOperationUpdates(t *testing.T) {
752752 }
753753
754754 ctx := context .Background ()
755+
756+ operations := make ([]* core.Operation , 0 )
757+ opID := fftypes .NewUUID ()
758+ op := & core.Operation {
759+ ID : opID ,
760+ Plugin : "blockchain" ,
761+ Type : core .OpTypeBlockchainPinBatch ,
762+ Status : core .OpStatusInitialized ,
763+ }
764+ op2ID := fftypes .NewUUID ()
765+ op2 := & core.Operation {
766+ ID : op2ID ,
767+ Plugin : "blockchain" ,
768+ Type : core .OpTypeBlockchainContractDeploy ,
769+ Status : core .OpStatusInitialized ,
770+ }
771+ operations = append (operations , op , op2 )
772+
755773 submittedUpdate := & core.OperationUpdate {
756- NamespacedOpID : "ns1:" + fftypes . NewUUID () .String (),
774+ NamespacedOpID : "ns1:" + opID .String (),
757775 Status : core .OpStatusSucceeded ,
758776 ErrorMessage : "my-error-message" ,
759777 }
760778
761779 submittedUpdate2 := & core.OperationUpdate {
762- NamespacedOpID : "ns1:" + fftypes . NewUUID () .String (),
780+ NamespacedOpID : "ns1:" + op2ID .String (),
763781 Status : core .OpStatusSucceeded ,
764782 ErrorMessage : "my-error-message" ,
765783 }
766784
767- // Create a channel to receive the onCommit signal
785+ mdi := om .database .(* databasemocks.Plugin )
786+ mdi .On ("GetOperations" , ctx , "ns1" , mock .Anything ).Return (operations , nil , nil )
787+
768788 err := om .SubmitBulkOperationUpdates (ctx , []* core.OperationUpdate {submittedUpdate , submittedUpdate2 })
769789 assert .NoError (t , err )
790+ }
791+
792+ func TestSubmitBulkOperationUpdatesIgnoredUpdate (t * testing.T ) {
793+ om , cancel := newTestOperations (t )
794+ defer cancel ()
795+
796+ om .updater .workQueues = []chan * core.OperationUpdate {
797+ make (chan * core.OperationUpdate , 1 ),
798+ }
799+
800+ ctx := context .Background ()
801+
802+ operations := make ([]* core.Operation , 0 )
803+ opID := fftypes .NewUUID ()
804+ op := & core.Operation {
805+ ID : opID ,
806+ Plugin : "blockchain" ,
807+ Type : core .OpTypeBlockchainPinBatch ,
808+ Status : core .OpStatusInitialized ,
809+ }
810+ operations = append (operations , op )
770811
771- // update := <-om.updater.workQueues[0]
772- // assert.Equal(t, submittedUpdate.NamespacedOpID, update.NamespacedOpID)
773- // assert.Equal(t, core.OpStatusSucceeded, update.Status)
774- // update.OnComplete()
812+ submittedUpdate := & core.OperationUpdate {
813+ NamespacedOpID : "different-namespace:" + opID .String (),
814+ Status : core .OpStatusSucceeded ,
815+ ErrorMessage : "my-error-message" ,
816+ }
775817
776- // update2 := <-om.updater.workQueues[0]
777- // assert.Equal(t, submittedUpdate2.NamespacedOpID, update2.NamespacedOpID)
778- // assert.Equal(t, core.OpStatusSucceeded, update2.Status)
779- // update2.OnComplete()
780- // Wait for oncommit signal
818+ err := om .SubmitBulkOperationUpdates (ctx , []* core.OperationUpdate {submittedUpdate })
819+ assert .NoError (t , err )
820+ }
821+
822+ func TestSubmitBulkOperationUpdatesIgnoredBadID (t * testing.T ) {
823+ om , cancel := newTestOperations (t )
824+ defer cancel ()
825+
826+ om .updater .workQueues = []chan * core.OperationUpdate {
827+ make (chan * core.OperationUpdate , 1 ),
828+ }
829+
830+ ctx := context .Background ()
831+
832+ submittedUpdate := & core.OperationUpdate {
833+ NamespacedOpID : "ns1:BAD-UUID" ,
834+ Status : core .OpStatusSucceeded ,
835+ ErrorMessage : "my-error-message" ,
836+ }
837+
838+ err := om .SubmitBulkOperationUpdates (ctx , []* core.OperationUpdate {submittedUpdate })
839+ assert .NoError (t , err )
840+ }
841+
842+ func TestSubmitBulkOperationUpdatesError (t * testing.T ) {
843+ om , cancel := newTestOperations (t )
844+ defer cancel ()
845+
846+ om .updater .workQueues = []chan * core.OperationUpdate {
847+ make (chan * core.OperationUpdate , 1 ),
848+ }
849+
850+ ctx := context .Background ()
851+
852+ operations := make ([]* core.Operation , 0 )
853+ opID := fftypes .NewUUID ()
854+ op := & core.Operation {
855+ ID : opID ,
856+ Plugin : "blockchain" ,
857+ Type : core .OpTypeBlockchainPinBatch ,
858+ Status : core .OpStatusInitialized ,
859+ }
860+ operations = append (operations , op )
861+
862+ submittedUpdate := & core.OperationUpdate {
863+ NamespacedOpID : "ns1:" + opID .String (),
864+ Status : core .OpStatusSucceeded ,
865+ ErrorMessage : "my-error-message" ,
866+ }
867+
868+ mdi := om .database .(* databasemocks.Plugin )
869+ mdi .On ("GetOperations" , ctx , "ns1" , mock .Anything ).Return (operations , nil , errors .New ("Failed to get operations" ))
870+
871+ err := om .SubmitBulkOperationUpdates (ctx , []* core.OperationUpdate {submittedUpdate })
872+ assert .Error (t , err )
781873}
0 commit comments