Examples for using Client Mock


I apologize in advance if my question is too basic. Are there any examples for using Client mock? Specifically for setting custom return values and errors of the workflow when using we.Get?

we = client.GetWorkflow(workflowID)
var result interface{}
we.Get(ctx, &result)


You don’t really need to use the mocks package (we are considering removing it, see Remove mocks package · Issue #61 · temporalio/sdk-go · GitHub). Rather, it’s just an interface, use whatever your favorite approach is to mock an interface, be that a mocking lib you are used to or just impl the interface directly. For example (untested):

type fakeClient struct { client.Client }

func (fakeClient) GetWorkflow(context.Context, string, string) client.WorkflowRun {
  return fakeWorkflowRun{}

type fakeWorkflowRun struct { client.WorkflowRun }

func (fakeWorkflowRun) Get(context.Context, interface{}) error {
  // Do whatever you want
  return nil

Thank you!