Skip to content

Commit ecf10b1

Browse files
authored
Fix UpsertSearchAttributes mocking (#1027)
1 parent d0966cf commit ecf10b1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

internal/internal_workflow_testsuite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,10 +1855,10 @@ func (env *testWorkflowEnvironmentImpl) UpsertSearchAttributes(attributes map[st
18551855
// mock found, check if return is error
18561856
args := []interface{}{attributes}
18571857
mockRet := env.mock.MethodCalled(mockMethod, args...)
1858-
if len(mockRet) != 1 {
1858+
if len(mockRet) > 1 {
18591859
panic(fmt.Sprintf("mock of UpsertSearchAttributes should return only one error"))
18601860
}
1861-
if mockRet[0] != nil {
1861+
if len(mockRet) == 1 && mockRet[0] != nil {
18621862
return mockRet[0].(error)
18631863
}
18641864
}

internal/internal_workflow_testsuite_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,16 @@ func (s *WorkflowTestSuiteUnitTest) Test_MockUpsertSearchAttributes() {
13861386
s.Nil(env.GetWorkflowError())
13871387
env.AssertExpectations(s.T())
13881388

1389+
// mock no return
1390+
env = s.NewTestWorkflowEnvironment()
1391+
env.OnUpsertSearchAttributes(map[string]interface{}{}).Once()
1392+
env.OnUpsertSearchAttributes(map[string]interface{}{"CustomIntField": 1}).Once()
1393+
1394+
env.ExecuteWorkflow(workflowFn)
1395+
s.True(env.IsWorkflowCompleted())
1396+
s.Nil(env.GetWorkflowError())
1397+
env.AssertExpectations(s.T())
1398+
13891399
// mix no-mock and mock is not support
13901400
}
13911401

0 commit comments

Comments
 (0)