-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixes client StartWorkflowOptions timeouts
- Loading branch information
Showing
11 changed files
with
2,188 additions
and
799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
with-expecter: true | ||
packages: | ||
go.temporal.io/sdk/internal: | ||
config: | ||
dir: mocks/go.temporal.io/sdk/clientutils | ||
outpkg: clientutils | ||
replace-type: | ||
- go.temporal.io/sdk/internal=go.temporal.io/sdk/client | ||
interfaces: | ||
WorkflowRun: {} | ||
go.temporal.io/sdk/client: | ||
config: | ||
replace-type: | ||
- go.temporal.io/sdk/internal=go.temporal.io/sdk/client | ||
interfaces: | ||
Client: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
examplev1 "github.com/cludden/protoc-gen-go-temporal/gen/example/v1" | ||
clientMock "github.com/cludden/protoc-gen-go-temporal/mocks/go.temporal.io/sdk/client" | ||
"github.com/cludden/protoc-gen-go-temporal/mocks/go.temporal.io/sdk/clientutils" | ||
"github.com/stretchr/testify/mock" | ||
"github.com/stretchr/testify/require" | ||
"go.temporal.io/sdk/client" | ||
) | ||
|
||
func TestCreateFooStartWorkflowOptions(t *testing.T) { | ||
ctx, require := context.Background(), require.New(t) | ||
|
||
c := clientMock.NewMockClient(t) | ||
c.On("ExecuteWorkflow", mock.Anything, mock.Anything, examplev1.CreateFooWorkflowName, mock.Anything).Return( | ||
func(ctx context.Context, opts client.StartWorkflowOptions, workflow any, params ...any) (run client.WorkflowRun, err error) { | ||
if opts.ID != "create-foo/bar" { | ||
err = errors.Join(err, fmt.Errorf("expected workflow id to equal 'create-foo/bar', got: %q", opts.ID)) | ||
} | ||
if opts.WorkflowExecutionTimeout != time.Hour { | ||
err = errors.Join(err, fmt.Errorf("expected workflow execution timeout to equal 1h, got: %s", opts.WorkflowExecutionTimeout)) | ||
} | ||
if len(opts.SearchAttributes) != 2 { | ||
err = errors.Join(err, fmt.Errorf("expected 2 search attributes, got: %d", len(opts.SearchAttributes))) | ||
} | ||
if raw, ok := opts.SearchAttributes["foo"]; !ok { | ||
err = errors.Join(err, fmt.Errorf("expected search attributes to contain 'foo' attribute")) | ||
} else if v, ok := raw.(string); !ok { | ||
err = errors.Join(err, fmt.Errorf("expected 'foo' attribute to be string, got: %T", raw)) | ||
} else if v != "bar" { | ||
err = errors.Join(err, fmt.Errorf("expected 'foo' to equal 'bar', got: %q", v)) | ||
} | ||
if raw, ok := opts.SearchAttributes["created_at"]; !ok { | ||
err = errors.Join(err, fmt.Errorf("expected search attributes to contain 'created_at' attribute")) | ||
} else if v, ok := raw.(time.Time); !ok { | ||
err = errors.Join(err, fmt.Errorf("expected 'created_at' attribute to be string, got: %T", raw)) | ||
} else if time.Since(v) > time.Second { | ||
err = errors.Join(err, fmt.Errorf("expected 'created_at' to be within 1s: %q", v)) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
return clientutils.NewMockWorkflowRun(t), nil | ||
}, | ||
) | ||
example := examplev1.NewExampleClient(c) | ||
_, err := example.CreateFooAsync(ctx, &examplev1.CreateFooRequest{Name: "bar"}) | ||
require.NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.