Skip to content

Commit 46e2e86

Browse files
authored
Fix mock error in OnUpsertSearchAttributes (#1017)
1 parent 15ec566 commit 46e2e86

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

internal/error_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var (
5858
testErrorDetails4 = testStruct2{"a string", 321, &[]string{"eat", "code"}}
5959
)
6060

61-
func (tes *testErrorStruct) Error() string{
61+
func (tes *testErrorStruct) Error() string {
6262
return tes.message
6363
}
6464

internal/internal_worker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ func (s *internalWorkerTestSuite) TearDownTest() {
136136

137137
func (s *internalWorkerTestSuite) createLocalActivityMarkerDataForTest(activityID, activityType string) []byte {
138138
lamd := localActivityMarkerData{
139-
ActivityID: activityID,
139+
ActivityID: activityID,
140140
ActivityType: activityType,
141-
ReplayTime: time.Now(),
141+
ReplayTime: time.Now(),
142142
}
143143

144144
// encode marker data

internal/internal_workflow_testsuite.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,19 +1849,21 @@ func getMockMethodForGetVersion(changeID string) string {
18491849
}
18501850

18511851
func (env *testWorkflowEnvironmentImpl) UpsertSearchAttributes(attributes map[string]interface{}) error {
1852-
attr, err := validateAndSerializeSearchAttributes(attributes)
1853-
1854-
env.workflowInfo.SearchAttributes = mergeSearchAttributes(env.workflowInfo.SearchAttributes, attr)
1855-
18561852
mockMethod := mockMethodForUpsertSearchAttributes
1857-
if _, ok := env.expectedMockCalls[mockMethod]; !ok {
1858-
// mock not found
1859-
return err
1853+
if _, ok := env.expectedMockCalls[mockMethod]; ok {
1854+
// mock found, check if return is error
1855+
args := []interface{}{attributes}
1856+
mockRet := env.mock.MethodCalled(mockMethod, args...)
1857+
if len(mockRet) != 1 {
1858+
panic(fmt.Sprintf("mock of UpsertSearchAttributes should return only one error"))
1859+
}
1860+
if mockRet[0] != nil {
1861+
return mockRet[0].(error)
1862+
}
18601863
}
18611864

1862-
args := []interface{}{attributes}
1863-
env.mock.MethodCalled(mockMethod, args...)
1864-
1865+
attr, err := validateAndSerializeSearchAttributes(attributes)
1866+
env.workflowInfo.SearchAttributes = mergeSearchAttributes(env.workflowInfo.SearchAttributes, attr)
18651867
return err
18661868
}
18671869

internal/internal_workflow_testsuite_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,24 @@ func (s *WorkflowTestSuiteUnitTest) Test_MockUpsertSearchAttributes() {
13891389
// mix no-mock and mock is not support
13901390
}
13911391

1392+
func (s *WorkflowTestSuiteUnitTest) Test_MockUpsertSearchAttributes_OnError() {
1393+
workflowFn := func(ctx Context) error {
1394+
attr := map[string]interface{}{}
1395+
attr["CustomIntField"] = 1
1396+
err := UpsertSearchAttributes(ctx, attr)
1397+
s.Error(err)
1398+
return err
1399+
}
1400+
1401+
env := s.NewTestWorkflowEnvironment()
1402+
env.OnUpsertSearchAttributes(map[string]interface{}{"CustomIntField": 1}).Return(errors.New("test error")).Once()
1403+
1404+
env.ExecuteWorkflow(workflowFn)
1405+
s.True(env.IsWorkflowCompleted())
1406+
s.Error(env.GetWorkflowError())
1407+
env.AssertExpectations(s.T())
1408+
}
1409+
13921410
func (s *WorkflowTestSuiteUnitTest) Test_ActivityWithThriftTypes() {
13931411
actualValues := []string{}
13941412
retVal := &shared.WorkflowExecution{WorkflowId: common.StringPtr("retwID2"), RunId: common.StringPtr("retrID2")}

internal/registry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ type testWorkflowStruct struct{}
193193
type testActivityStruct struct{}
194194

195195
func (ts *testWorkflowStruct) Method(ctx Context) error { return nil }
196-
func (ts *testActivityStruct) Method() error { return nil }
196+
func (ts *testActivityStruct) Method() error { return nil }
197197

198198
func testActivityFunction() error { return nil }
199199
func testWorkflowFunction(ctx Context) error { return nil }

0 commit comments

Comments
 (0)