Skip to content

Commit

Permalink
expose replayer options
Browse files Browse the repository at this point in the history
  • Loading branch information
vikstrous committed Jul 24, 2024
1 parent 53c26c7 commit 67d430d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ There are two functions in this library that make it easy to write fixture based
See `example/main_test.go` for an example of how to use them.
```go
func GetWorkflowHistoriesBundle(ctx context.Context, client *tempts.Client, w *tempts.WorkflowWithImpl) ([]byte, error)
func ReplayWorkflow(historiesBytes []byte, w *tempts.WorkflowWithImpl) error
func ReplayWorkflow(historiesBytes []byte, w *tempts.WorkflowWithImpl, opts worker.WorkflowReplayerOptions) error
```

## User guide by example
Expand Down Expand Up @@ -309,7 +309,7 @@ if err != nil {
t.Fatal(err)
}
// Now store historiesData somewhere! (Or don't and make sure your test is always connected to a temporal instance with example workflow runs)
err := tempts.ReplayWorkflow(historiesData, exampleWorkflow)
err := tempts.ReplayWorkflow(historiesData, exampleWorkflow, worker.WorkflowReplayerOptions{})
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion example/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/vikstrous/tempts"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/worker"
)

var record bool
Expand Down Expand Up @@ -49,7 +50,7 @@ func testReplayability(t *testing.T, workflowDeclaration tempts.WorkflowDeclarat
}
}

err := tempts.ReplayWorkflow(historiesData, fn)
err := tempts.ReplayWorkflow(historiesData, fn, worker.WorkflowReplayerOptions{})
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 5 additions & 2 deletions replaytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type historiesData struct {
}

// ReplayWorkflow is meant to be used in tests with the output of GetWorkflowHistoriesBundle to check if the given workflow implementation (fn) is compatible with previous executions captured at the time when GetWorkflowHistoriesBundle was run.
func ReplayWorkflow(historiesBytes []byte, fn any) error {
func ReplayWorkflow(historiesBytes []byte, fn any, opts worker.WorkflowReplayerOptions) error {
var historiesData historiesData
err := json.Unmarshal(historiesBytes, &historiesData)
if err != nil {
Expand All @@ -101,7 +101,10 @@ func ReplayWorkflow(historiesBytes []byte, fn any) error {
if len(historiesData.Histories) == 0 {
return fmt.Errorf("no histories available")
}
replayer := worker.NewWorkflowReplayer()
replayer, err := worker.NewWorkflowReplayerWithOptions(opts)
if err != nil {
return fmt.Errorf("failed to create replayer: %w", err)
}
replayer.RegisterWorkflowWithOptions(fn, workflow.RegisterOptions{
Name: historiesData.WorkflowName,
})
Expand Down

0 comments on commit 67d430d

Please sign in to comment.