@@ -28,10 +28,12 @@ func TestListApprovalTasks(t *testing.T) {
28
28
{
29
29
Name : "tekton" ,
30
30
Input : "reject" ,
31
+ Type : "User" ,
31
32
},
32
33
{
33
34
Name : "cli" ,
34
35
Input : "pending" ,
36
+ Type : "User" ,
35
37
},
36
38
},
37
39
NumberOfApprovalsRequired : 2 ,
@@ -44,6 +46,7 @@ func TestListApprovalTasks(t *testing.T) {
44
46
ApproversResponse : []v1alpha1.ApproverState {
45
47
{
46
48
Name : "tekton" ,
49
+ Type : "User" ,
47
50
Response : "rejected" ,
48
51
},
49
52
},
@@ -60,10 +63,12 @@ func TestListApprovalTasks(t *testing.T) {
60
63
{
61
64
Name : "tekton" ,
62
65
Input : "approve" ,
66
+ Type : "User" ,
63
67
},
64
68
{
65
69
Name : "cli" ,
66
70
Input : "approve" ,
71
+ Type : "User" ,
67
72
},
68
73
},
69
74
NumberOfApprovalsRequired : 2 ,
@@ -76,11 +81,13 @@ func TestListApprovalTasks(t *testing.T) {
76
81
ApproversResponse : []v1alpha1.ApproverState {
77
82
{
78
83
Name : "tekton" ,
79
- Response : "approve" ,
84
+ Type : "User" ,
85
+ Response : "approved" ,
80
86
},
81
87
{
82
88
Name : "cli" ,
83
- Response : "approve" ,
89
+ Type : "User" ,
90
+ Response : "approved" ,
84
91
},
85
92
},
86
93
State : "approved" ,
@@ -96,10 +103,12 @@ func TestListApprovalTasks(t *testing.T) {
96
103
{
97
104
Name : "tekton" ,
98
105
Input : "pending" ,
106
+ Type : "User" ,
99
107
},
100
108
{
101
109
Name : "cli" ,
102
110
Input : "pending" ,
111
+ Type : "User" ,
103
112
},
104
113
},
105
114
NumberOfApprovalsRequired : 2 ,
@@ -125,10 +134,12 @@ func TestListApprovalTasks(t *testing.T) {
125
134
{
126
135
Name : "tekton" ,
127
136
Input : "reject" ,
137
+ Type : "User" ,
128
138
},
129
139
{
130
140
Name : "cli" ,
131
141
Input : "pending" ,
142
+ Type : "User" ,
132
143
},
133
144
},
134
145
NumberOfApprovalsRequired : 2 ,
@@ -141,6 +152,7 @@ func TestListApprovalTasks(t *testing.T) {
141
152
ApproversResponse : []v1alpha1.ApproverState {
142
153
{
143
154
Name : "tekton" ,
155
+ Type : "User" ,
144
156
Response : "rejected" ,
145
157
},
146
158
},
@@ -157,10 +169,12 @@ func TestListApprovalTasks(t *testing.T) {
157
169
{
158
170
Name : "tekton" ,
159
171
Input : "approve" ,
172
+ Type : "User" ,
160
173
},
161
174
{
162
175
Name : "cli" ,
163
176
Input : "approve" ,
177
+ Type : "User" ,
164
178
},
165
179
},
166
180
NumberOfApprovalsRequired : 2 ,
@@ -173,11 +187,13 @@ func TestListApprovalTasks(t *testing.T) {
173
187
ApproversResponse : []v1alpha1.ApproverState {
174
188
{
175
189
Name : "tekton" ,
176
- Response : "approve" ,
190
+ Type : "User" ,
191
+ Response : "approved" ,
177
192
},
178
193
{
179
194
Name : "cli" ,
180
- Response : "approve" ,
195
+ Type : "User" ,
196
+ Response : "approved" ,
181
197
},
182
198
},
183
199
State : "approved" ,
@@ -193,10 +209,12 @@ func TestListApprovalTasks(t *testing.T) {
193
209
{
194
210
Name : "tekton" ,
195
211
Input : "pending" ,
212
+ Type : "User" ,
196
213
},
197
214
{
198
215
Name : "cli" ,
199
216
Input : "pending" ,
217
+ Type : "User" ,
200
218
},
201
219
},
202
220
NumberOfApprovalsRequired : 2 ,
@@ -280,6 +298,159 @@ func TestListApprovalTasks(t *testing.T) {
280
298
281
299
}
282
300
301
+ // Test individual functions for group functionality
302
+ func TestPendingApprovalsWithGroups (t * testing.T ) {
303
+ tests := []struct {
304
+ name string
305
+ at * v1alpha1.ApprovalTask
306
+ expected int
307
+ }{
308
+ {
309
+ name : "group with multiple members responded" ,
310
+ at : & v1alpha1.ApprovalTask {
311
+ Spec : v1alpha1.ApprovalTaskSpec {
312
+ NumberOfApprovalsRequired : 3 ,
313
+ },
314
+ Status : v1alpha1.ApprovalTaskStatus {
315
+ ApproversResponse : []v1alpha1.ApproverState {
316
+ {
317
+ Name : "admin-group" ,
318
+ Type : "Group" ,
319
+ GroupMembers : []v1alpha1.GroupMemberState {
320
+ {Name : "alice" , Response : "approved" },
321
+ {Name : "bob" , Response : "rejected" },
322
+ },
323
+ },
324
+ },
325
+ },
326
+ },
327
+ expected : 1 , // 3 required - 2 responded = 1 pending
328
+ },
329
+ {
330
+ name : "mixed user and group responses" ,
331
+ at : & v1alpha1.ApprovalTask {
332
+ Spec : v1alpha1.ApprovalTaskSpec {
333
+ NumberOfApprovalsRequired : 4 ,
334
+ },
335
+ Status : v1alpha1.ApprovalTaskStatus {
336
+ ApproversResponse : []v1alpha1.ApproverState {
337
+ {
338
+ Name : "direct-user" ,
339
+ Type : "User" ,
340
+ Response : "approved" ,
341
+ },
342
+ {
343
+ Name : "dev-team" ,
344
+ Type : "Group" ,
345
+ GroupMembers : []v1alpha1.GroupMemberState {
346
+ {Name : "charlie" , Response : "approved" },
347
+ {Name : "david" , Response : "approved" },
348
+ },
349
+ },
350
+ },
351
+ },
352
+ },
353
+ expected : 1 , // 4 required - 3 responded = 1 pending
354
+ },
355
+ {
356
+ name : "no responses" ,
357
+ at : & v1alpha1.ApprovalTask {
358
+ Spec : v1alpha1.ApprovalTaskSpec {
359
+ NumberOfApprovalsRequired : 2 ,
360
+ },
361
+ Status : v1alpha1.ApprovalTaskStatus {
362
+ ApproversResponse : []v1alpha1.ApproverState {},
363
+ },
364
+ },
365
+ expected : 2 , // 2 required - 0 responded = 2 pending
366
+ },
367
+ }
368
+
369
+ for _ , tt := range tests {
370
+ t .Run (tt .name , func (t * testing.T ) {
371
+ result := pendingApprovals (tt .at )
372
+ if result != tt .expected {
373
+ t .Errorf ("pendingApprovals() = %d, expected %d" , result , tt .expected )
374
+ }
375
+ })
376
+ }
377
+ }
378
+
379
+ func TestRejectedWithGroups (t * testing.T ) {
380
+ tests := []struct {
381
+ name string
382
+ at * v1alpha1.ApprovalTask
383
+ expected int
384
+ }{
385
+ {
386
+ name : "group with multiple rejections" ,
387
+ at : & v1alpha1.ApprovalTask {
388
+ Status : v1alpha1.ApprovalTaskStatus {
389
+ ApproversResponse : []v1alpha1.ApproverState {
390
+ {
391
+ Name : "qa-team" ,
392
+ Type : "Group" ,
393
+ GroupMembers : []v1alpha1.GroupMemberState {
394
+ {Name : "tester1" , Response : "rejected" },
395
+ {Name : "tester2" , Response : "rejected" },
396
+ {Name : "tester3" , Response : "approved" },
397
+ },
398
+ },
399
+ },
400
+ },
401
+ },
402
+ expected : 2 , // 2 rejections from group members
403
+ },
404
+ {
405
+ name : "mixed user and group rejections" ,
406
+ at : & v1alpha1.ApprovalTask {
407
+ Status : v1alpha1.ApprovalTaskStatus {
408
+ ApproversResponse : []v1alpha1.ApproverState {
409
+ {
410
+ Name : "direct-user" ,
411
+ Type : "User" ,
412
+ Response : "rejected" ,
413
+ },
414
+ {
415
+ Name : "admin-group" ,
416
+ Type : "Group" ,
417
+ GroupMembers : []v1alpha1.GroupMemberState {
418
+ {Name : "admin1" , Response : "rejected" },
419
+ {Name : "admin2" , Response : "approved" },
420
+ },
421
+ },
422
+ },
423
+ },
424
+ },
425
+ expected : 2 , // 1 direct user + 1 group member rejected = 2
426
+ },
427
+ {
428
+ name : "no rejections" ,
429
+ at : & v1alpha1.ApprovalTask {
430
+ Status : v1alpha1.ApprovalTaskStatus {
431
+ ApproversResponse : []v1alpha1.ApproverState {
432
+ {
433
+ Name : "user1" ,
434
+ Type : "User" ,
435
+ Response : "approved" ,
436
+ },
437
+ },
438
+ },
439
+ },
440
+ expected : 0 , // no rejections
441
+ },
442
+ }
443
+
444
+ for _ , tt := range tests {
445
+ t .Run (tt .name , func (t * testing.T ) {
446
+ result := rejected (tt .at )
447
+ if result != tt .expected {
448
+ t .Errorf ("rejected() = %d, expected %d" , result , tt .expected )
449
+ }
450
+ })
451
+ }
452
+ }
453
+
283
454
func command (t * testing.T , approvaltasks []* v1alpha1.ApprovalTask , ns []* corev1.Namespace , dc dynamic.Interface ) * cobra.Command {
284
455
cs , _ := test .SeedTestData (t , test.Data {Approvaltasks : approvaltasks , Namespaces : ns })
285
456
p := & test.Params {ApprovalTask : cs .ApprovalTask , Kube : cs .Kube , Dynamic : dc }
0 commit comments