-
Notifications
You must be signed in to change notification settings - Fork 202
/
replay_test.go
46 lines (37 loc) · 1.29 KB
/
replay_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package helloworld
import (
"testing"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"go.temporal.io/api/workflowservicemock/v1"
"go.temporal.io/sdk/worker"
)
type replayTestSuite struct {
suite.Suite
mockCtrl *gomock.Controller
service *workflowservicemock.MockWorkflowServiceClient
}
func TestReplayTestSuite(t *testing.T) {
s := new(replayTestSuite)
suite.Run(t, s)
}
func (s *replayTestSuite) SetupTest() {
s.mockCtrl = gomock.NewController(s.T())
s.service = workflowservicemock.NewMockWorkflowServiceClient(s.mockCtrl)
}
func (s *replayTestSuite) TearDownTest() {
s.mockCtrl.Finish() // assert mock’s expectations
}
// This replay test is the recommended way to make sure changing workflow code is backward compatible without non-deterministic errors.
// "helloworld.json" can be downloaded from Temporal CLI:
//
// tctl wf show -w hello_world_workflowID --output_filename ./helloworld.json
//
// Or from Temporal Web UI. And you may need to change workflowType in the first event.
func (s *replayTestSuite) TestReplayWorkflowHistoryFromFile() {
replayer := worker.NewWorkflowReplayer()
replayer.RegisterWorkflow(Workflow)
err := replayer.ReplayWorkflowHistoryFromJSONFile(nil, "helloworld.json")
require.NoError(s.T(), err)
}