@@ -71,11 +71,17 @@ func TestComputeReconcileResult(t *testing.T) {
7171 afterFunc func (t * WithT , obj conditions.Setter , patchOpts * patch.HelperOptions )
7272 }{
7373 {
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+ },
7679 recErr : nil ,
7780 wantResult : ctrl.Result {RequeueAfter : testSuccessInterval },
7881 wantErr : false ,
82+ assertConditions : []metav1.Condition {
83+ * conditions .TrueCondition (meta .ReadyCondition , meta .SucceededReason , "foo" ),
84+ },
7985 afterFunc : func (t * WithT , obj conditions.Setter , patchOpts * patch.HelperOptions ) {
8086 t .Expect (patchOpts .IncludeStatusObservedGeneration ).To (BeTrue ())
8187 },
@@ -85,10 +91,14 @@ func TestComputeReconcileResult(t *testing.T) {
8591 result : ResultSuccess ,
8692 beforeFunc : func (obj conditions.Setter ) {
8793 conditions .MarkReconciling (obj , "NewRevision" , "new revision" )
94+ conditions .MarkTrue (obj , meta .ReadyCondition , meta .SucceededReason , "foo" )
8895 },
8996 recErr : nil ,
9097 wantResult : ctrl.Result {RequeueAfter : testSuccessInterval },
9198 wantErr : false ,
99+ assertConditions : []metav1.Condition {
100+ * conditions .TrueCondition (meta .ReadyCondition , meta .SucceededReason , "foo" ),
101+ },
92102 afterFunc : func (t * WithT , obj conditions.Setter , patchOpts * patch.HelperOptions ) {
93103 t .Expect (patchOpts .IncludeStatusObservedGeneration ).To (BeTrue ())
94104 t .Expect (conditions .IsUnknown (obj , meta .ReconcilingCondition )).To (BeTrue ())
@@ -367,3 +377,58 @@ func TestFailureRecovery(t *testing.T) {
367377 })
368378 }
369379}
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