@@ -23,6 +23,7 @@ package internal
23
23
24
24
import (
25
25
"context"
26
+ "github.com/stretchr/testify/mock"
26
27
"github.com/stretchr/testify/suite"
27
28
"strings"
28
29
"testing"
@@ -129,6 +130,53 @@ func TestWorkflowReturnNil(t *testing.T) {
129
130
require .NoError (t , err )
130
131
}
131
132
133
+ func HelloWorkflow (ctx Context , name string ) (string , error ) {
134
+ ctx = WithActivityOptions (ctx , ActivityOptions {
135
+ ScheduleToCloseTimeout : time .Hour ,
136
+ StartToCloseTimeout : time .Hour ,
137
+ ScheduleToStartTimeout : time .Hour ,
138
+ })
139
+ var result string
140
+ err := ExecuteActivity (ctx , HelloActivity , name ).Get (ctx , & result )
141
+ return result , err
142
+ }
143
+
144
+ func HelloActivity (ctx context.Context , name string ) (string , error ) {
145
+ return "Hello " + name + "!" , nil
146
+ }
147
+
148
+ func TestWorkflowMockingWithoutRegistration (t * testing.T ) {
149
+ testSuite := & WorkflowTestSuite {}
150
+ env := testSuite .NewTestWorkflowEnvironment ()
151
+ env .OnWorkflow (HelloWorkflow , mock .Anything , mock .Anything ).Return (
152
+ func (ctx Context , person string ) (string , error ) {
153
+ return "Hello " + person + "!" , nil
154
+ })
155
+ // Workflow is mocked, no activity registration required
156
+ env .ExecuteWorkflow (HelloWorkflow , "Cadence" )
157
+ require .NoError (t , env .GetWorkflowError ())
158
+ var result string
159
+ err := env .GetWorkflowResult (& result )
160
+ require .NoError (t , err )
161
+ require .Equal (t , "Hello Cadence!" , result )
162
+ }
163
+
164
+ func TestActivityMockingWithoutRegistration (t * testing.T ) {
165
+ testSuite := & WorkflowTestSuite {}
166
+ env := testSuite .NewTestWorkflowEnvironment ()
167
+ env .OnActivity (HelloActivity , mock .Anything , mock .Anything ).Return (
168
+ func (ctx context.Context , person string ) (string , error ) {
169
+ return "Goodbye " + person + "!" , nil
170
+ })
171
+ // Registration of activity not required
172
+ env .RegisterWorkflow (HelloWorkflow )
173
+ env .ExecuteWorkflow (HelloWorkflow , "Cadence" )
174
+ require .NoError (t , env .GetWorkflowError ())
175
+ var result string
176
+ err := env .GetWorkflowResult (& result )
177
+ require .NoError (t , err )
178
+ require .Equal (t , "Goodbye Cadence!" , result )
179
+
132
180
type InterceptorTestSuite struct {
133
181
suite.Suite
134
182
WorkflowTestSuite
0 commit comments