Skip to content

Commit

Permalink
Add unit tests for SideEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
3vilhamster committed Nov 6, 2024
1 parent 6774654 commit fe6d89c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/internal_event_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,31 @@ func TestWorkflowExecutionEventHandler_ProcessEvent_no_error_events(t *testing.T
}
}

func TestSideEffect(t *testing.T) {
t.Run("replay", func(t *testing.T) {
weh := testWorkflowExecutionEventHandler(t, newRegistry())
weh.workflowEnvironmentImpl.isReplay = true
weh.sideEffectResult[weh.counterID] = []byte("test")
weh.SideEffect(func() ([]byte, error) {
t.Error("side effect should not be called during replay")
t.Failed()
return nil, assert.AnError
}, func(result []byte, err error) {
assert.NoError(t, err)
assert.Equal(t, "test", string(result))
})
})
t.Run("success", func(t *testing.T) {
weh := testWorkflowExecutionEventHandler(t, newRegistry())
weh.SideEffect(func() ([]byte, error) {
return []byte("test"), nil
}, func(result []byte, err error) {
assert.NoError(t, err)
assert.Equal(t, "test", string(result))
})
})
}

func testWorkflowExecutionEventHandler(t *testing.T, registry *registry) *workflowExecutionEventHandlerImpl {
return newWorkflowExecutionEventHandler(
testWorkflowInfo,
Expand Down

0 comments on commit fe6d89c

Please sign in to comment.