diff --git a/.golangci.yaml b/.golangci.yaml index 8e47c48..0830a78 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,6 +1,6 @@ -run: - skip-files: - - doc.go +issues: + exclude-files: + - doc\.go$ linters: enable: - asasalint @@ -31,10 +31,20 @@ linters-settings: statements: 60 grouper: + # Require the use of grouped global 'const' declarations. + # Default: false const-require-grouping: true + # Require the use of a single 'import' declaration only. + # Default: false import-require-single-import: true + # Require the use of grouped 'import' declarations. + # Default: false import-require-grouping: true + # Require the use of grouped global 'type' declarations. + # Default: false type-require-grouping: true + # Require the use of grouped global 'var' declarations. + # Default: false var-require-grouping: true gci: @@ -50,10 +60,6 @@ linters-settings: # If `true`, make the section order the same as the order of `sections`. # Default: false custom-order: true - - # gocritic: - # disabled-checks: - # - ruleguard # unused dogsled: # Checks assignments with too many blank identifiers. @@ -72,4 +78,3 @@ linters-settings: - 140 - name: use-any severity: warning - diff --git a/go.mod b/go.mod index 9eba783..0ea3e40 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.21.0 require ( github.com/gobeam/stringy v0.0.7 github.com/stretchr/testify v1.9.0 + go.temporal.io/api v1.32.0 go.temporal.io/sdk v1.26.1 ) @@ -20,7 +21,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/robfig/cron v1.2.0 // indirect github.com/stretchr/objx v0.5.2 // indirect - go.temporal.io/api v1.32.0 // indirect golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect diff --git a/queues/mocks_test.go b/queues/mocks_test.go new file mode 100644 index 0000000..4fe629b --- /dev/null +++ b/queues/mocks_test.go @@ -0,0 +1,188 @@ +// nolint +package queues_test + +import ( + "context" + + "go.temporal.io/api/enums/v1" + "go.temporal.io/api/operatorservice/v1" + "go.temporal.io/api/workflowservice/v1" + "go.temporal.io/sdk/client" + "go.temporal.io/sdk/converter" + "go.temporal.io/sdk/testsuite" +) + +type ( + MockClient struct { + env *testsuite.TestWorkflowEnvironment + } +) + +func NewMockClient(env *testsuite.TestWorkflowEnvironment) *MockClient { + return &MockClient{env: env} +} + +func (m *MockClient) ExecuteWorkflow( + ctx context.Context, options client.StartWorkflowOptions, workflow any, args ...any, +) (client.WorkflowRun, error) { + m.env.ExecuteWorkflow(workflow, args...) + return &mockWorkflowRun{env: m.env}, nil +} + +func (m *MockClient) GetWorkflow(ctx context.Context, workflowID string, runID string) client.WorkflowRun { + return &mockWorkflowRun{env: m.env} +} + +func (m *MockClient) SignalWorkflow(ctx context.Context, workflowID string, runID string, signalName string, arg any) error { + m.env.SignalWorkflow(signalName, arg) + + return nil +} + +func (m *MockClient) SignalWithStartWorkflow( + ctx context.Context, workflowID string, signalName string, signalArg any, options client.StartWorkflowOptions, workflow any, workflowArgs ...any, +) (client.WorkflowRun, error) { + return nil, nil +} + +func (m *MockClient) CancelWorkflow(ctx context.Context, workflowID string, runID string) error { + return nil +} + +func (m *MockClient) TerminateWorkflow(ctx context.Context, workflowID string, runID string, reason string, details ...any) error { + return nil +} + +func (m *MockClient) GetWorkflowHistory( + ctx context.Context, workflowID string, runID string, isLongPoll bool, filterType enums.HistoryEventFilterType, +) client.HistoryEventIterator { + return nil +} + +func (m *MockClient) CompleteActivity(ctx context.Context, taskToken []byte, result any, err error) error { + return nil +} + +func (m *MockClient) CompleteActivityByID( + ctx context.Context, namespace, workflowID, runID, activityID string, result any, err error, +) error { + return nil +} + +func (m *MockClient) RecordActivityHeartbeat(ctx context.Context, taskToken []byte, details ...any) error { + return nil +} + +func (m *MockClient) RecordActivityHeartbeatByID(ctx context.Context, namespace, workflowID, runID, activityID string, details ...any) error { + return nil +} + +func (m *MockClient) ListClosedWorkflow(ctx context.Context, request *workflowservice.ListClosedWorkflowExecutionsRequest) (*workflowservice.ListClosedWorkflowExecutionsResponse, error) { + return &workflowservice.ListClosedWorkflowExecutionsResponse{}, nil +} + +func (m *MockClient) ListOpenWorkflow(ctx context.Context, request *workflowservice.ListOpenWorkflowExecutionsRequest) (*workflowservice.ListOpenWorkflowExecutionsResponse, error) { + return &workflowservice.ListOpenWorkflowExecutionsResponse{}, nil +} + +func (m *MockClient) ListWorkflow(ctx context.Context, request *workflowservice.ListWorkflowExecutionsRequest) (*workflowservice.ListWorkflowExecutionsResponse, error) { + return &workflowservice.ListWorkflowExecutionsResponse{}, nil +} + +func (m *MockClient) ListArchivedWorkflow(ctx context.Context, request *workflowservice.ListArchivedWorkflowExecutionsRequest) (*workflowservice.ListArchivedWorkflowExecutionsResponse, error) { + return &workflowservice.ListArchivedWorkflowExecutionsResponse{}, nil +} + +func (m *MockClient) ScanWorkflow(ctx context.Context, request *workflowservice.ScanWorkflowExecutionsRequest) (*workflowservice.ScanWorkflowExecutionsResponse, error) { + return &workflowservice.ScanWorkflowExecutionsResponse{}, nil +} + +func (m *MockClient) CountWorkflow(ctx context.Context, request *workflowservice.CountWorkflowExecutionsRequest) (*workflowservice.CountWorkflowExecutionsResponse, error) { + return &workflowservice.CountWorkflowExecutionsResponse{}, nil +} + +func (m *MockClient) GetSearchAttributes(ctx context.Context) (*workflowservice.GetSearchAttributesResponse, error) { + return &workflowservice.GetSearchAttributesResponse{}, nil +} + +func (m *MockClient) QueryWorkflow(ctx context.Context, workflowID string, runID string, queryType string, args ...any) (converter.EncodedValue, error) { + return nil, nil +} + +func (m *MockClient) QueryWorkflowWithOptions(ctx context.Context, request *client.QueryWorkflowWithOptionsRequest) (*client.QueryWorkflowWithOptionsResponse, error) { + return &client.QueryWorkflowWithOptionsResponse{}, nil +} + +func (m *MockClient) DescribeWorkflowExecution(ctx context.Context, workflowID, runID string) (*workflowservice.DescribeWorkflowExecutionResponse, error) { + return &workflowservice.DescribeWorkflowExecutionResponse{}, nil +} + +func (m *MockClient) DescribeTaskQueue(ctx context.Context, taskqueue string, taskqueueType enums.TaskQueueType) (*workflowservice.DescribeTaskQueueResponse, error) { + return &workflowservice.DescribeTaskQueueResponse{}, nil +} + +func (m *MockClient) ResetWorkflowExecution(ctx context.Context, request *workflowservice.ResetWorkflowExecutionRequest) (*workflowservice.ResetWorkflowExecutionResponse, error) { + return &workflowservice.ResetWorkflowExecutionResponse{}, nil +} + +func (m *MockClient) UpdateWorkerBuildIdCompatibility(ctx context.Context, options *client.UpdateWorkerBuildIdCompatibilityOptions) error { + return nil +} + +func (m *MockClient) GetWorkerBuildIdCompatibility(ctx context.Context, options *client.GetWorkerBuildIdCompatibilityOptions) (*client.WorkerBuildIDVersionSets, error) { + return &client.WorkerBuildIDVersionSets{}, nil +} + +func (m *MockClient) GetWorkerTaskReachability(ctx context.Context, options *client.GetWorkerTaskReachabilityOptions) (*client.WorkerTaskReachability, error) { + return &client.WorkerTaskReachability{}, nil +} + +func (m *MockClient) CheckHealth(ctx context.Context, request *client.CheckHealthRequest) (*client.CheckHealthResponse, error) { + return &client.CheckHealthResponse{}, nil +} + +func (m *MockClient) UpdateWorkflow(ctx context.Context, workflowID string, workflowRunID string, updateName string, args ...any) (client.WorkflowUpdateHandle, error) { + return nil, nil +} + +func (m *MockClient) UpdateWorkflowWithOptions(ctx context.Context, request *client.UpdateWorkflowWithOptionsRequest) (client.WorkflowUpdateHandle, error) { + return nil, nil +} + +func (m *MockClient) GetWorkflowUpdateHandle(ref client.GetWorkflowUpdateHandleOptions) client.WorkflowUpdateHandle { + return nil +} + +func (m *MockClient) WorkflowService() workflowservice.WorkflowServiceClient { + return nil +} + +func (m *MockClient) OperatorService() operatorservice.OperatorServiceClient { + return nil +} + +func (m *MockClient) ScheduleClient() client.ScheduleClient { + return nil +} + +func (m *MockClient) Close() {} + +type mockWorkflowRun struct { + env *testsuite.TestWorkflowEnvironment +} + +func (r *mockWorkflowRun) GetID() string { + return "mock-workflow-id" +} + +func (r *mockWorkflowRun) GetRunID() string { + return "mock-run-id" +} + +func (r *mockWorkflowRun) Get(ctx context.Context, valuePtr any) error { + return r.env.GetWorkflowResult(valuePtr) +} + +func (r *mockWorkflowRun) GetWithOptions(ctx context.Context, valuePtr any, options client.WorkflowRunGetOptions) error { + return r.env.GetWorkflowResult(valuePtr) +}