@@ -1274,6 +1274,92 @@ func (s *WorkflowTestSuiteUnitTest) Test_GetVersion() {
12741274 env .AssertExpectations (s .T ())
12751275}
12761276
1277+ func (s * WorkflowTestSuiteUnitTest ) Test_GetVersion_ExecuteWithMinVersion () {
1278+ oldActivity := func (ctx context.Context , msg string ) (string , error ) {
1279+ return "hello" + "_" + msg , nil
1280+ }
1281+ newActivity := func (ctx context.Context , msg string ) (string , error ) {
1282+ return "hello" + "_" + msg , nil
1283+ }
1284+ workflowFn := func (ctx Context ) error {
1285+ ctx = WithActivityOptions (ctx , s .activityOptions )
1286+ var f Future
1287+ v := GetVersion (ctx , "test_change_id" , DefaultVersion , 2 , ExecuteWithMinVersion ())
1288+ if v == DefaultVersion {
1289+ f = ExecuteActivity (ctx , oldActivity , "ols_msg" )
1290+ } else {
1291+ f = ExecuteActivity (ctx , newActivity , "new_msg" )
1292+ }
1293+ err := f .Get (ctx , nil ) // wait for result
1294+ if err != nil {
1295+ return err
1296+ }
1297+
1298+ // test no search attributes
1299+ wfInfo := GetWorkflowInfo (ctx )
1300+ s .Nil (wfInfo .SearchAttributes )
1301+ return err
1302+ }
1303+
1304+ env := s .NewTestWorkflowEnvironment ()
1305+ env .RegisterWorkflow (workflowFn )
1306+ env .RegisterActivity (oldActivity )
1307+ env .RegisterActivity (newActivity )
1308+ env .OnActivity (oldActivity , mock .Anything , "ols_msg" ).Return ("hello_ols_msg" , nil ).Once ()
1309+ env .ExecuteWorkflow (workflowFn )
1310+
1311+ s .True (env .IsWorkflowCompleted ())
1312+ s .Nil (env .GetWorkflowError ())
1313+ env .AssertExpectations (s .T ())
1314+ }
1315+
1316+ func (s * WorkflowTestSuiteUnitTest ) Test_GetVersion_ExecuteWithVersion () {
1317+ oldActivity := func (ctx context.Context , msg string ) (string , error ) {
1318+ return "hello" + "_" + msg , nil
1319+ }
1320+ newActivity := func (ctx context.Context , msg string ) (string , error ) {
1321+ return "hello" + "_" + msg , nil
1322+ }
1323+ workflowFn := func (ctx Context ) error {
1324+ ctx = WithActivityOptions (ctx , s .activityOptions )
1325+ var f Future
1326+ v := GetVersion (ctx , "test_change_id" , DefaultVersion , 2 , ExecuteWithVersion (1 ))
1327+ if v == DefaultVersion {
1328+ f = ExecuteActivity (ctx , oldActivity , "ols_msg" )
1329+ } else {
1330+ f = ExecuteActivity (ctx , newActivity , "new_msg" )
1331+ }
1332+ err := f .Get (ctx , nil ) // wait for result
1333+ if err != nil {
1334+ return err
1335+ }
1336+
1337+ // test searchable change version
1338+ wfInfo := GetWorkflowInfo (ctx )
1339+ s .NotNil (wfInfo .SearchAttributes )
1340+ changeVersionsBytes , ok := wfInfo .SearchAttributes .IndexedFields [CadenceChangeVersion ]
1341+ s .True (ok )
1342+ var changeVersions []string
1343+ err = json .Unmarshal (changeVersionsBytes , & changeVersions )
1344+ s .NoError (err )
1345+ s .Equal (1 , len (changeVersions ))
1346+ s .Equal ("test_change_id-1" , changeVersions [0 ])
1347+
1348+ return err
1349+ }
1350+
1351+ env := s .NewTestWorkflowEnvironment ()
1352+ env .RegisterWorkflow (workflowFn )
1353+ env .RegisterActivity (oldActivity )
1354+ env .RegisterActivity (newActivity )
1355+ env .OnActivity (newActivity , mock .Anything , "new_msg" ).Return ("hello new_mock_msg" , nil ).Once ()
1356+ env .ExecuteWorkflow (workflowFn )
1357+
1358+ s .True (env .IsWorkflowCompleted ())
1359+ s .Nil (env .GetWorkflowError ())
1360+ env .AssertExpectations (s .T ())
1361+ }
1362+
12771363func (s * WorkflowTestSuiteUnitTest ) Test_MockGetVersion () {
12781364 oldActivity := func (ctx context.Context , msg string ) (string , error ) {
12791365 return "hello" + "_" + msg , nil
0 commit comments