From 67d430de21bbf056327fbf171c25f0b417398f99 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Wed, 24 Jul 2024 01:00:08 +0000 Subject: [PATCH] expose replayer options --- README.md | 4 ++-- example/replay_test.go | 3 ++- replaytest.go | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 45c6621..1f2658a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) } diff --git a/example/replay_test.go b/example/replay_test.go index 0804283..45fa9fd 100644 --- a/example/replay_test.go +++ b/example/replay_test.go @@ -10,6 +10,7 @@ import ( "github.com/vikstrous/tempts" "go.temporal.io/sdk/client" + "go.temporal.io/sdk/worker" ) var record bool @@ -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) } diff --git a/replaytest.go b/replaytest.go index afdce66..505117c 100644 --- a/replaytest.go +++ b/replaytest.go @@ -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 { @@ -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, })