Skip to content

Commit

Permalink
Migrate integration tests to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Nov 28, 2024
1 parent 246636a commit ff5d5b3
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 129 deletions.
30 changes: 15 additions & 15 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ var (
)

var (
errUnsupportedOperation = fmt.Errorf("unsupported operation")
errInvalidServerResponse = fmt.Errorf("invalid server response")
errInvalidWorkflowOperation = fmt.Errorf("invalid WithStartOperation")
errUnsupportedOperation = fmt.Errorf("unsupported operation")
errInvalidServerResponse = fmt.Errorf("invalid server response")
errInvalidWithStartWorkflowOperation = fmt.Errorf("invalid WithStartWorkflowOperation")
)

const (
Expand Down Expand Up @@ -1189,6 +1189,13 @@ func (wc *WorkflowClient) UpdateWithStartWorkflow(
return nil, err
}

if updateOptions.RunID != "" {
return nil, errors.New("invalid UpdateWorkflowOptions: RunID cannot be set for UpdateWithStartWorkflow because the workflow might not be running")
}
if updateOptions.FirstExecutionRunID != "" {
return nil, errors.New("invalid UpdateWorkflowOptions: FirstExecutionRunID cannot be set for UpdateWithStartWorkflow because the workflow might not be running")
}

updateInput, err := createUpdateWorkflowInput(updateOptions)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1721,19 +1728,12 @@ func (w *workflowClientInterceptor) UpdateWithStartWorkflow(
updateInput *ClientUpdateWorkflowInput,
startOperation *WithStartWorkflowOperation,
) (WorkflowUpdateHandle, error) {
if updateInput.RunID != "" {
return nil, errors.New("RunID and StartWorkflowInput cannot both be set")
}
if updateInput.FirstExecutionRunID != "" {
return nil, errors.New("FirstExecutionRunID and StartWorkflowInput cannot both be set")
}

// Create start request
if err := startOperation.markExecuted(); err != nil {
return nil, fmt.Errorf("%w: %w", errInvalidWorkflowOperation, err)
return nil, fmt.Errorf("%w: %w", errInvalidWithStartWorkflowOperation, err)
}
if startOperation.err != nil {
return nil, fmt.Errorf("%w: %w", errInvalidWorkflowOperation, startOperation.err)
return nil, fmt.Errorf("%w: %w", errInvalidWithStartWorkflowOperation, startOperation.err)
}
startReq, err := w.createStartWorkflowRequest(ctx, startOperation.input)
if err != nil {
Expand All @@ -1743,7 +1743,7 @@ func (w *workflowClientInterceptor) UpdateWithStartWorkflow(
// Create update request
updateReq, err := w.createUpdateWorkflowRequest(ctx, updateInput)
if err != nil {
return nil, fmt.Errorf("%w: %w", errInvalidWorkflowOperation, err)
return nil, fmt.Errorf("%w: %w", errInvalidWithStartWorkflowOperation, err)
}
if updateReq.WorkflowExecution.WorkflowId == "" {
updateReq.WorkflowExecution.WorkflowId = startReq.WorkflowId
Expand Down Expand Up @@ -1782,7 +1782,7 @@ func (w *workflowClientInterceptor) UpdateWithStartWorkflow(
}
handle, err := w.updateHandleFromResponse(ctx, updateReq.WaitPolicy.LifecycleStage, updateResp)
if err != nil {
return nil, fmt.Errorf("%w: %w", errInvalidWorkflowOperation, err)
return nil, fmt.Errorf("%w: %w", errInvalidWithStartWorkflowOperation, err)
}
return handle, nil
}
Expand Down Expand Up @@ -1857,7 +1857,7 @@ func (w *workflowClientInterceptor) updateWithStartWorkflow(
}
case *workflowservice.ExecuteMultiOperationRequest_Operation_UpdateWorkflow:
if !errors.As(opErr, &abortedErr) {
startErr = fmt.Errorf("%w: %w", errInvalidWorkflowOperation, opErr)
startErr = fmt.Errorf("%w: %w", errInvalidWithStartWorkflowOperation, opErr)
}
default:
// this would only happen if a case statement for a newly added operation is missing above
Expand Down
Loading

0 comments on commit ff5d5b3

Please sign in to comment.