Skip to content

Commit

Permalink
chore(queues): mock client for queues
Browse files Browse the repository at this point in the history
  • Loading branch information
Yousuf Jawwad committed Aug 14, 2024
1 parent cba72d5 commit 150eb94
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 9 deletions.
21 changes: 13 additions & 8 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
skip-files:
- doc.go
issues:
exclude-files:
- doc\.go$
linters:
enable:
- asasalint
Expand Down Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -72,4 +78,3 @@ linters-settings:
- 140
- name: use-any
severity: warning

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
Expand Down
188 changes: 188 additions & 0 deletions queues/mocks_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 150eb94

Please sign in to comment.