@@ -71,11 +71,17 @@ func TestComputeReconcileResult(t *testing.T) {
71
71
afterFunc func (t * WithT , obj conditions.Setter , patchOpts * patch.HelperOptions )
72
72
}{
73
73
{
74
- name : "successful result" ,
75
- result : ResultSuccess ,
74
+ name : "successful result" ,
75
+ result : ResultSuccess ,
76
+ beforeFunc : func (obj conditions.Setter ) {
77
+ conditions .MarkTrue (obj , meta .ReadyCondition , meta .SucceededReason , "foo" )
78
+ },
76
79
recErr : nil ,
77
80
wantResult : ctrl.Result {RequeueAfter : testSuccessInterval },
78
81
wantErr : false ,
82
+ assertConditions : []metav1.Condition {
83
+ * conditions .TrueCondition (meta .ReadyCondition , meta .SucceededReason , "foo" ),
84
+ },
79
85
afterFunc : func (t * WithT , obj conditions.Setter , patchOpts * patch.HelperOptions ) {
80
86
t .Expect (patchOpts .IncludeStatusObservedGeneration ).To (BeTrue ())
81
87
},
@@ -85,10 +91,14 @@ func TestComputeReconcileResult(t *testing.T) {
85
91
result : ResultSuccess ,
86
92
beforeFunc : func (obj conditions.Setter ) {
87
93
conditions .MarkReconciling (obj , "NewRevision" , "new revision" )
94
+ conditions .MarkTrue (obj , meta .ReadyCondition , meta .SucceededReason , "foo" )
88
95
},
89
96
recErr : nil ,
90
97
wantResult : ctrl.Result {RequeueAfter : testSuccessInterval },
91
98
wantErr : false ,
99
+ assertConditions : []metav1.Condition {
100
+ * conditions .TrueCondition (meta .ReadyCondition , meta .SucceededReason , "foo" ),
101
+ },
92
102
afterFunc : func (t * WithT , obj conditions.Setter , patchOpts * patch.HelperOptions ) {
93
103
t .Expect (patchOpts .IncludeStatusObservedGeneration ).To (BeTrue ())
94
104
t .Expect (conditions .IsUnknown (obj , meta .ReconcilingCondition )).To (BeTrue ())
@@ -367,3 +377,58 @@ func TestFailureRecovery(t *testing.T) {
367
377
})
368
378
}
369
379
}
380
+
381
+ func TestAddOptionWithStatusObservedGeneration (t * testing.T ) {
382
+ tests := []struct {
383
+ name string
384
+ beforeFunc func (obj conditions.Setter )
385
+ patchOpts []patch.Option
386
+ want bool
387
+ }{
388
+ {
389
+ name : "no conditions" ,
390
+ want : false ,
391
+ },
392
+ {
393
+ name : "some condition" ,
394
+ beforeFunc : func (obj conditions.Setter ) {
395
+ conditions .MarkTrue (obj , meta .ReadyCondition , meta .SucceededReason , "foo" )
396
+ },
397
+ want : true ,
398
+ },
399
+ {
400
+ name : "existing option with conditions" ,
401
+ beforeFunc : func (obj conditions.Setter ) {
402
+ conditions .MarkTrue (obj , meta .ReadyCondition , meta .SucceededReason , "foo" )
403
+ },
404
+ patchOpts : []patch.Option {patch.WithForceOverwriteConditions {}, patch.WithStatusObservedGeneration {}},
405
+ want : true ,
406
+ },
407
+ {
408
+ name : "existing option, no conditions, can't remove" ,
409
+ patchOpts : []patch.Option {patch.WithForceOverwriteConditions {}, patch.WithStatusObservedGeneration {}},
410
+ want : true ,
411
+ },
412
+ }
413
+
414
+ for _ , tt := range tests {
415
+ t .Run (tt .name , func (t * testing.T ) {
416
+ g := NewWithT (t )
417
+
418
+ obj := & sourcev1.GitRepository {}
419
+
420
+ if tt .beforeFunc != nil {
421
+ tt .beforeFunc (obj )
422
+ }
423
+
424
+ tt .patchOpts = addPatchOptionWithStatusObservedGeneration (obj , tt .patchOpts )
425
+
426
+ // Apply the options and evaluate the result.
427
+ options := & patch.HelperOptions {}
428
+ for _ , opt := range tt .patchOpts {
429
+ opt .ApplyToHelper (options )
430
+ }
431
+ g .Expect (options .IncludeStatusObservedGeneration ).To (Equal (tt .want ))
432
+ })
433
+ }
434
+ }
0 commit comments