|
1 | 1 | package accounthook_workflow
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "errors" |
| 5 | + "strings" |
4 | 6 | "testing"
|
5 | 7 |
|
6 | 8 | accounthook_events "github.com/nucleuscloud/neosync/internal/ee/events"
|
@@ -42,3 +44,34 @@ func Test_ProcessAccountHook(t *testing.T) {
|
42 | 44 |
|
43 | 45 | env.AssertExpectations(t)
|
44 | 46 | }
|
| 47 | + |
| 48 | +func Test_ProcessAccountHook_Error(t *testing.T) { |
| 49 | + var ts testsuite.WorkflowTestSuite |
| 50 | + env := ts.NewTestWorkflowEnvironment() |
| 51 | + |
| 52 | + var hooksByEventActivity *hooks_by_event_activity.Activity |
| 53 | + env.OnActivity(hooksByEventActivity.GetAccountHooksByEvent, mock.Anything, mock.Anything). |
| 54 | + Return(&hooks_by_event_activity.RunHooksByEventResponse{ |
| 55 | + HookIds: []string{"hook1", "hook2"}, |
| 56 | + }, nil).Once() |
| 57 | + |
| 58 | + var executeHookActivity *execute_hook_activity.Activity |
| 59 | + env.OnActivity(executeHookActivity.ExecuteAccountHook, mock.Anything, mock.Anything). |
| 60 | + Return(nil, errors.New("error")) |
| 61 | + |
| 62 | + env.RegisterWorkflow(ProcessAccountHook) |
| 63 | + |
| 64 | + env.ExecuteWorkflow(ProcessAccountHook, &ProcessAccountHookRequest{ |
| 65 | + Event: accounthook_events.NewEvent_JobRunCreated("123", "456", "789"), |
| 66 | + }) |
| 67 | + |
| 68 | + env.AssertExpectations(t) |
| 69 | + |
| 70 | + require.True(t, env.IsWorkflowCompleted()) |
| 71 | + |
| 72 | + workflowErr := env.GetWorkflowError() |
| 73 | + require.Error(t, workflowErr) |
| 74 | + require.Contains(t, workflowErr.Error(), "error executing hook:") |
| 75 | + // The way temporal wraps these they show up more than the number of hooks |
| 76 | + require.GreaterOrEqual(t, strings.Count(workflowErr.Error(), "error executing hook:"), 2) |
| 77 | +} |
0 commit comments