@@ -754,6 +754,22 @@ func TestGetVersion(t *testing.T) {
754754 res := weh .GetVersion ("test" , 1 , 3 )
755755 assert .Equal (t , Version (2 ), res )
756756 })
757+ t .Run ("version exists, ExecuteWithVersion is used" , func (t * testing.T ) {
758+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
759+ weh .changeVersions = map [string ]Version {
760+ "test" : 2 ,
761+ }
762+ res := weh .GetVersion ("test" , 1 , 3 , ExecuteWithVersion (3 ))
763+ assert .Equal (t , Version (2 ), res )
764+ })
765+ t .Run ("version exists, ExecuteWithMinVersion is used" , func (t * testing.T ) {
766+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
767+ weh .changeVersions = map [string ]Version {
768+ "test" : 2 ,
769+ }
770+ res := weh .GetVersion ("test" , 1 , 3 , ExecuteWithMinVersion ())
771+ assert .Equal (t , Version (2 ), res )
772+ })
757773 t .Run ("version doesn't exist in replay" , func (t * testing.T ) {
758774 weh := testWorkflowExecutionEventHandler (t , newRegistry ())
759775 weh .isReplay = true
@@ -770,6 +786,55 @@ func TestGetVersion(t *testing.T) {
770786 assert .Equal (t , Version (3 ), weh .changeVersions ["test" ])
771787 assert .Equal (t , []byte (`["test-3"]` ), weh .workflowInfo .SearchAttributes .IndexedFields [CadenceChangeVersion ], "ensure search attributes are updated" )
772788 })
789+ t .Run ("version doesn't exist, ExecuteWithVersion is used" , func (t * testing.T ) {
790+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
791+ res := weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithVersion (2 ))
792+ assert .Equal (t , Version (2 ), res )
793+ require .Contains (t , weh .changeVersions , "test" )
794+ assert .Equal (t , Version (2 ), weh .changeVersions ["test" ])
795+ assert .Equal (t , []byte (`["test-2"]` ), weh .workflowInfo .SearchAttributes .IndexedFields [CadenceChangeVersion ], "ensure search attributes are updated" )
796+ })
797+ t .Run ("version doesn't exist, ExecuteWithVersion is used, DefaultVersion is used" , func (t * testing.T ) {
798+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
799+ res := weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithVersion (DefaultVersion ))
800+ assert .Equal (t , DefaultVersion , res )
801+ require .Contains (t , weh .changeVersions , "test" )
802+ assert .Equal (t , DefaultVersion , weh .changeVersions ["test" ])
803+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
804+ })
805+ t .Run ("version doesn't exist, ExecuteWithMinVersion is used, min is non DefaultVersion" , func (t * testing.T ) {
806+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
807+ res := weh .GetVersion ("test" , 1 , 3 , ExecuteWithMinVersion ())
808+ assert .Equal (t , Version (1 ), res )
809+ require .Contains (t , weh .changeVersions , "test" )
810+ assert .Equal (t , Version (1 ), weh .changeVersions ["test" ])
811+ assert .Equal (t , []byte (`["test-1"]` ), weh .workflowInfo .SearchAttributes .IndexedFields [CadenceChangeVersion ], "ensure search attributes are updated" )
812+ })
813+ t .Run ("version doesn't exist, ExecuteWithMinVersion is used, DefaultVersion is used" , func (t * testing.T ) {
814+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
815+ res := weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithMinVersion ())
816+ assert .Equal (t , DefaultVersion , res )
817+ require .Contains (t , weh .changeVersions , "test" )
818+ assert .Equal (t , DefaultVersion , weh .changeVersions ["test" ])
819+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
820+ })
821+
822+ t .Run ("version doesn't exist, ExecuteWithVersion is used, version > maximum version" , func (t * testing.T ) {
823+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
824+ assert .PanicsWithValue (t , `Workflow code is too old to support version 10 for "test" changeID. The maximum supported version is 3` , func () {
825+ weh .GetVersion ("test" , DefaultVersion , 3 , ExecuteWithVersion (10 ))
826+ })
827+
828+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
829+ })
830+ t .Run ("version doesn't exist, ExecuteWithVersion is used, version < minimum version" , func (t * testing.T ) {
831+ weh := testWorkflowExecutionEventHandler (t , newRegistry ())
832+ assert .PanicsWithValue (t , `Workflow code removed support of version 0. for "test" changeID. The oldest supported version is 1` , func () {
833+ weh .GetVersion ("test" , 1 , 3 , ExecuteWithVersion (0 ))
834+ })
835+
836+ require .Nil (t , weh .workflowInfo .SearchAttributes , "ensure search attributes are not updated" )
837+ })
773838}
774839
775840func TestMutableSideEffect (t * testing.T ) {
@@ -982,6 +1047,13 @@ func TestWorkflowExecutionEnvironment_NewTimer_immediate_calls(t *testing.T) {
9821047}
9831048
9841049func testWorkflowExecutionEventHandler (t * testing.T , registry * registry ) * workflowExecutionEventHandlerImpl {
1050+ var testWorkflowInfo = & WorkflowInfo {
1051+ WorkflowType : WorkflowType {
1052+ Name : "test" ,
1053+ Path : "" ,
1054+ },
1055+ }
1056+
9851057 return newWorkflowExecutionEventHandler (
9861058 testWorkflowInfo ,
9871059 func (result []byte , err error ) {},
@@ -996,13 +1068,6 @@ func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workfl
9961068 ).(* workflowExecutionEventHandlerImpl )
9971069}
9981070
999- var testWorkflowInfo = & WorkflowInfo {
1000- WorkflowType : WorkflowType {
1001- Name : "test" ,
1002- Path : "" ,
1003- },
1004- }
1005-
10061071func getSerializedDetails [T , V any ](t * testing.T , id T , data V ) []byte {
10071072 converter := defaultDataConverter {}
10081073 res , err := converter .ToData (id , data )
0 commit comments