@@ -23,8 +23,6 @@ package internal
23
23
24
24
import (
25
25
"context"
26
- "github.com/stretchr/testify/mock"
27
- "github.com/stretchr/testify/suite"
28
26
"strings"
29
27
"testing"
30
28
"time"
@@ -129,120 +127,3 @@ func TestWorkflowReturnNil(t *testing.T) {
129
127
err := env .GetWorkflowResult (& r )
130
128
require .NoError (t , err )
131
129
}
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
-
180
- type InterceptorTestSuite struct {
181
- suite.Suite
182
- WorkflowTestSuite
183
-
184
- env * TestWorkflowEnvironment
185
- testFactory InterceptorFactory
186
- }
187
-
188
- type InterceptorFactory struct {
189
- workflowInterceptorInvocationCounter int
190
- childWorkflowInterceptorInvocationCounter int
191
- }
192
-
193
- type Interceptor struct {
194
- WorkflowInterceptorBase
195
- workflowInterceptorInvocationCounter * int
196
- childWorkflowInterceptorInvocationCounter * int
197
- }
198
-
199
- func (i * Interceptor ) ExecuteWorkflow (ctx Context , workflowType string , args ... interface {}) []interface {} {
200
- * i.workflowInterceptorInvocationCounter += 1
201
- return i .Next .ExecuteWorkflow (ctx , workflowType , args ... )
202
- }
203
- func (i * Interceptor ) ExecuteChildWorkflow (ctx Context , workflowType string , args ... interface {}) ChildWorkflowFuture {
204
- * i .childWorkflowInterceptorInvocationCounter + = 1
205
- return i .Next .ExecuteChildWorkflow (ctx , workflowType , args ... )
206
- }
207
-
208
- func (f * InterceptorFactory ) NewInterceptor (_ * WorkflowInfo , next WorkflowInterceptor ) WorkflowInterceptor {
209
- return & Interceptor {
210
- WorkflowInterceptorBase : WorkflowInterceptorBase {
211
- Next : next ,
212
- },
213
- workflowInterceptorInvocationCounter : & f .workflowInterceptorInvocationCounter ,
214
- childWorkflowInterceptorInvocationCounter : & f .childWorkflowInterceptorInvocationCounter ,
215
- }
216
- }
217
-
218
- func (s * InterceptorTestSuite ) SetupTest () {
219
- // Create a test workflow environment with the trace interceptor configured.
220
- s.env = s .NewTestWorkflowEnvironment ()
221
- s.testFactory = InterceptorFactory {}
222
- s .env .SetWorkerOptions (WorkerOptions {
223
- WorkflowInterceptorChainFactories : []WorkflowInterceptorFactory {
224
- & s .testFactory ,
225
- },
226
- })
227
- }
228
-
229
- func TestInterceptorTestSuite (t * testing .T ) {
230
- suite .Run (t , new (InterceptorTestSuite ))
231
- }
232
-
233
- func (s * InterceptorTestSuite ) Test_GeneralInterceptor_IsExecutedOnChildren () {
234
- r := s .Require ()
235
- childWf := func (ctx Context ) error {
236
- return nil
237
- }
238
- s .env .RegisterWorkflowWithOptions (childWf , RegisterWorkflowOptions {Name : "child" })
239
- wf := func (ctx Context ) error {
240
- return ExecuteChildWorkflow (ctx , childWf ).Get (ctx , nil )
241
- }
242
- s .env .RegisterWorkflowWithOptions (wf , RegisterWorkflowOptions {Name : "parent" })
243
- s .env .ExecuteWorkflow (wf )
244
- r.True (s .env .IsWorkflowCompleted ())
245
- r.NoError (s .env .GetWorkflowError ())
246
- r .Equal (s .testFactory .workflowInterceptorInvocationCounter , 2 )
247
- r .Equal (s .testFactory .childWorkflowInterceptorInvocationCounter , 1 )
248
- }
0 commit comments