I’m trying to wrap the temporal client and abstract ExecuteWorkflow and UpdateWorkflow etc. away. I.e.:
type Service struct {
client client.Client
}
func (s *Service) RunWorkflow(ctx context.Context, orderId string, checkoutMinutes int64) error {
_, err := s.client.ExecuteWorkflow(ctx, client.StartWorkflowOptions{
ID: orderId,
TaskQueue: "sometaskqueue",
}, someFunction, orderId, checkoutMinutes)
return err
}
func (s *Service) UpdateOrder(ctx context.Context, someData *SomeData) (*order.Order, error) {
handle, err := s.client.UpdateWorkflow(ctx, client.UpdateWorkflowOptions{
WorkflowID: someData.GetId(),
UpdateName: string(workflow.UpdateOrder),
Args: []interface{}{someData},
WaitForStage: client.WorkflowUpdateStageAccepted,
})
if err != nil {
return nil, fmt.Errorf("failed to update: %w", err)
}
orderResponse := order.Order{}
if err = handle.Get(ctx, &orderResponse); err != nil {
return nil, fmt.Errorf("failed to get order response: %w", err)
}
return &orderResponse, nil
}
And I want to test these methods on my workflow by creating a testsuite.TestWorkflowEnvironment.
And do a drop-in replacement of the temporal client in the Service struct (i.e. service.client = env).
Unfortunately testsuite.TestWorkflowEnvironment does not implement the client.Client interface. Is there any way to get hold of a client using the testsuite (or do I have to do a custom interface implementing select methods of both client.Client and testsuite.TestWorkflowEnvironment, something I’d rather avoid).