@@ -13,22 +13,79 @@ func reg_workflow1(ctx sync.Context) error {
13
13
return nil
14
14
}
15
15
16
- func Test_WorkflowRegistration (t * testing.T ) {
17
- r := NewRegistry ()
18
- require .NotNil (t , r )
19
-
20
- err := r .RegisterWorkflow (reg_workflow1 )
21
- require .NoError (t , err )
22
-
23
- x , err := r .GetWorkflow ("reg_workflow1" )
24
- require .NoError (t , err )
25
-
26
- fn , ok := x .(func (context sync.Context ) error )
27
- require .True (t , ok )
28
- require .NotNil (t , fn )
29
-
30
- err = fn (sync .Background ())
31
- require .NoError (t , err )
16
+ func TestRegistry_RegisterWorkflow (t * testing.T ) {
17
+ type args struct {
18
+ workflow Workflow
19
+ }
20
+ tests := []struct {
21
+ name string
22
+ args args
23
+ wantName string
24
+ wantErr bool
25
+ }{
26
+ {
27
+ name : "valid workflow" ,
28
+ args : args {
29
+ workflow : reg_workflow1 ,
30
+ },
31
+ wantName : "reg_workflow1" ,
32
+ },
33
+ {
34
+ name : "valid workflow with results" ,
35
+ args : args {
36
+ workflow : func (ctx sync.Context ) (int , error ) { return 42 , nil },
37
+ },
38
+ },
39
+ {
40
+ name : "valid workflow with multiple parameters" ,
41
+ args : args {
42
+ workflow : func (ctx sync.Context , a , b int ) (int , error ) { return 42 , nil },
43
+ },
44
+ },
45
+ {
46
+ name : "missing parameter" ,
47
+ args : args {
48
+ workflow : func (ctx context.Context ) {},
49
+ },
50
+ wantErr : true ,
51
+ },
52
+ {
53
+ name : "missing error result" ,
54
+ args : args {
55
+ workflow : func (ctx sync.Context ) {},
56
+ },
57
+ wantErr : true ,
58
+ },
59
+ {
60
+ name : "missing error with results" ,
61
+ args : args {
62
+ workflow : func (ctx sync.Context ) int { return 42 },
63
+ },
64
+ wantErr : true ,
65
+ },
66
+ {
67
+ name : "missing error with results" ,
68
+ args : args {
69
+ workflow : func (ctx sync.Context ) int { return 42 },
70
+ },
71
+ wantErr : true ,
72
+ },
73
+ }
74
+ for _ , tt := range tests {
75
+ t .Run (tt .name , func (t * testing.T ) {
76
+ r := NewRegistry ()
77
+ if err := r .RegisterWorkflow (tt .args .workflow ); (err != nil ) != tt .wantErr {
78
+ t .Errorf ("Registry.RegisterWorkflow() error = %v, wantErr %v" , err , tt .wantErr )
79
+ t .FailNow ()
80
+ }
81
+
82
+ if tt .wantName != "" {
83
+ x , err := r .GetWorkflow (tt .wantName )
84
+ require .NoError (t , err )
85
+ require .NotNil (t , x )
86
+ }
87
+ })
88
+ }
32
89
}
33
90
34
91
func reg_activity (ctx context.Context ) error {
0 commit comments