@@ -16,17 +16,19 @@ import (
16
16
"github.com/cschleiden/go-workflows/internal/payload"
17
17
"github.com/cschleiden/go-workflows/internal/sync"
18
18
"github.com/cschleiden/go-workflows/internal/task"
19
+ "github.com/cschleiden/go-workflows/internal/workflowstate"
20
+ wf "github.com/cschleiden/go-workflows/workflow"
19
21
"github.com/stretchr/testify/require"
20
22
)
21
23
22
24
func newExecutor (r * Registry , i core.WorkflowInstance ) * executor {
23
- state := newWorkflowState (i , clock .New ())
24
- wfCtx , cancel := sync .WithCancel (WithWorkflowState (sync .Background (), state ))
25
+ s := workflowstate . NewWorkflowState (i , clock .New ())
26
+ wfCtx , cancel := sync .WithCancel (workflowstate . WithWorkflowState (sync .Background (), s ))
25
27
26
28
return & executor {
27
29
registry : r ,
28
30
workflow : NewWorkflow (reflect .ValueOf (workflow1 )),
29
- workflowState : state ,
31
+ workflowState : s ,
30
32
workflowCtx : wfCtx ,
31
33
workflowCtxCancel : cancel ,
32
34
logger : log .Default (),
@@ -74,15 +76,15 @@ func Test_ExecuteWorkflow(t *testing.T) {
74
76
75
77
require .Equal (t , 1 , workflowHits )
76
78
require .True (t , e .workflow .Completed ())
77
- require .Len (t , e .workflowState .commands , 1 )
79
+ require .Len (t , e .workflowState .Commands () , 1 )
78
80
}
79
81
80
82
var workflowActivityHit int
81
83
82
84
func workflowWithActivity (ctx sync.Context ) error {
83
85
workflowActivityHit ++
84
86
85
- f1 := ExecuteActivity (ctx , DefaultActivityOptions , activity1 , 42 )
87
+ f1 := wf . ExecuteActivity (ctx , wf . DefaultActivityOptions , activity1 , 42 )
86
88
87
89
var r int
88
90
err := f1 .Get (ctx , & r )
@@ -144,7 +146,7 @@ func Test_ReplayWorkflowWithActivityResult(t *testing.T) {
144
146
145
147
require .Equal (t , 2 , workflowActivityHit )
146
148
require .True (t , e .workflow .Completed ())
147
- require .Len (t , e .workflowState .commands , 1 )
149
+ require .Len (t , e .workflowState .Commands () , 1 )
148
150
}
149
151
150
152
func Test_ExecuteWorkflowWithActivityCommand (t * testing.T ) {
@@ -174,7 +176,7 @@ func Test_ExecuteWorkflowWithActivityCommand(t *testing.T) {
174
176
e .ExecuteTask (context .Background (), task )
175
177
176
178
require .Equal (t , 1 , workflowActivityHit )
177
- require .Len (t , e .workflowState .commands , 1 )
179
+ require .Len (t , e .workflowState .Commands () , 1 )
178
180
179
181
inputs , _ := converter .DefaultConverter .To (42 )
180
182
require .Equal (t , command.Command {
@@ -185,7 +187,7 @@ func Test_ExecuteWorkflowWithActivityCommand(t *testing.T) {
185
187
Name : "activity1" ,
186
188
Inputs : []payload.Payload {inputs },
187
189
},
188
- }, * e .workflowState .commands [0 ])
190
+ }, * e .workflowState .Commands () [0 ])
189
191
}
190
192
191
193
var workflowTimerHits int
@@ -194,7 +196,7 @@ func workflowWithTimer(ctx sync.Context) error {
194
196
workflowTimerHits ++
195
197
196
198
var r bool
197
- if err := ScheduleTimer (ctx , time .Millisecond * 5 ).Get (ctx , & r ); err != nil {
199
+ if err := wf . ScheduleTimer (ctx , time .Millisecond * 5 ).Get (ctx , & r ); err != nil {
198
200
panic ("error getting timer future" )
199
201
}
200
202
@@ -229,19 +231,19 @@ func Test_ExecuteWorkflowWithTimer(t *testing.T) {
229
231
e .ExecuteTask (context .Background (), task )
230
232
231
233
require .Equal (t , 1 , workflowTimerHits )
232
- require .Len (t , e .workflowState .commands , 1 )
234
+ require .Len (t , e .workflowState .Commands () , 1 )
233
235
234
- require .Equal (t , 1 , e .workflowState .commands [0 ].ID )
235
- require .Equal (t , command .CommandType_ScheduleTimer , e .workflowState .commands [0 ].Type )
236
+ require .Equal (t , 1 , e .workflowState .Commands () [0 ].ID )
237
+ require .Equal (t , command .CommandType_ScheduleTimer , e .workflowState .Commands () [0 ].Type )
236
238
}
237
239
238
240
var workflowWithSelectorHits int
239
241
240
242
func workflowWithSelector (ctx sync.Context ) error {
241
243
workflowWithSelectorHits ++
242
244
243
- f1 := ExecuteActivity (ctx , DefaultActivityOptions , activity1 , 42 )
244
- t := ScheduleTimer (ctx , time .Millisecond * 2 )
245
+ f1 := wf . ExecuteActivity (ctx , wf . DefaultActivityOptions , activity1 , 42 )
246
+ t := wf . ScheduleTimer (ctx , time .Millisecond * 2 )
245
247
246
248
sync .Select (
247
249
ctx ,
@@ -284,10 +286,10 @@ func Test_ExecuteWorkflowWithSelector(t *testing.T) {
284
286
e .ExecuteTask (context .Background (), task )
285
287
286
288
require .Equal (t , 1 , workflowWithSelectorHits )
287
- require .Len (t , e .workflowState .commands , 2 )
289
+ require .Len (t , e .workflowState .Commands () , 2 )
288
290
289
- require .Equal (t , command .CommandType_ScheduleTimer , e .workflowState .commands [0 ].Type )
290
- require .Equal (t , command .CommandType_ScheduleActivityTask , e .workflowState .commands [1 ].Type )
291
+ require .Equal (t , command .CommandType_ScheduleTimer , e .workflowState .Commands () [0 ].Type )
292
+ require .Equal (t , command .CommandType_ScheduleActivityTask , e .workflowState .Commands () [1 ].Type )
291
293
}
292
294
293
295
func Test_ExecuteNewEvents (t * testing.T ) {
@@ -332,7 +334,7 @@ func Test_ExecuteNewEvents(t *testing.T) {
332
334
require .NoError (t , err )
333
335
require .Equal (t , 1 , workflowActivityHit )
334
336
require .False (t , e .workflow .Completed ())
335
- require .Len (t , e .workflowState .commands , 0 )
337
+ require .Len (t , e .workflowState .Commands () , 0 )
336
338
337
339
h := []history.Event {}
338
340
h = append (h , oldTask .NewEvents ... )
@@ -360,14 +362,14 @@ func Test_ExecuteNewEvents(t *testing.T) {
360
362
require .NoError (t , err )
361
363
require .Equal (t , 2 , workflowActivityHit )
362
364
require .True (t , e .workflow .Completed ())
363
- require .Len (t , e .workflowState .commands , 1 )
365
+ require .Len (t , e .workflowState .Commands () , 1 )
364
366
}
365
367
366
368
var workflowSignalHits int
367
369
368
370
func workflowWithSignal1 (ctx sync.Context ) error {
369
371
370
- c := NewSignalChannel (ctx , "signal1" )
372
+ c := wf . NewSignalChannel (ctx , "signal1" )
371
373
c .Receive (ctx , nil )
372
374
373
375
workflowSignalHits ++
@@ -409,5 +411,5 @@ func Test_ExecuteWorkflowWithSignal(t *testing.T) {
409
411
410
412
require .Equal (t , 1 , workflowSignalHits )
411
413
require .True (t , e .workflow .Completed ())
412
- require .Len (t , e .workflowState .commands , 1 )
414
+ require .Len (t , e .workflowState .Commands () , 1 )
413
415
}
0 commit comments