@@ -18,7 +18,6 @@ package summarize
1818
1919import (
2020 "context"
21- "strings"
2221 "testing"
2322
2423 . "github.com/onsi/gomega"
@@ -41,8 +40,7 @@ func TestRecordReconcileReq(t *testing.T) {
4140 {
4241 name : "no reconcile req" ,
4342 afterFunc : func (t * WithT , obj client.Object ) {
44- // We don’t expect a reconcile request, and this is not an error anymore
45- t .Expect (object .GetStatusLastHandledReconcileAt (obj )).To (Equal ("" ))
43+ t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("" ))
4644 },
4745 },
4846 {
@@ -51,118 +49,77 @@ func TestRecordReconcileReq(t *testing.T) {
5149 object .SetStatusLastHandledReconcileAt (obj , "zzz" )
5250 },
5351 afterFunc : func (t * WithT , obj client.Object ) {
54- t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("zzz" ))
52+ t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("zzz" ))
5553 },
5654 },
5755 {
5856 name : "with reconcile req" ,
5957 beforeFunc : func (obj client.Object ) {
60- obj . SetAnnotations ( map [string ]string {
58+ annotations := map [string ]string {
6159 meta .ReconcileRequestAnnotation : "now" ,
62- })
60+ }
61+ obj .SetAnnotations (annotations )
6362 },
6463 afterFunc : func (t * WithT , obj client.Object ) {
65- t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("now" ))
64+ t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("now" ))
6665 },
6766 },
6867 {
6968 name : "empty reconcile annotation value" ,
7069 beforeFunc : func (obj client.Object ) {
71- obj . SetAnnotations ( map [string ]string {
70+ annotations := map [string ]string {
7271 meta .ReconcileRequestAnnotation : "" ,
73- })
72+ }
73+ obj .SetAnnotations (annotations )
7474 },
7575 afterFunc : func (t * WithT , obj client.Object ) {
76- t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("" ))
76+ t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("" ))
7777 },
7878 },
7979 {
8080 name : "whitespace-only reconcile annotation value" ,
8181 beforeFunc : func (obj client.Object ) {
82- obj . SetAnnotations ( map [string ]string {
82+ annotations := map [string ]string {
8383 meta .ReconcileRequestAnnotation : " " ,
84- })
84+ }
85+ obj .SetAnnotations (annotations )
8586 },
8687 afterFunc : func (t * WithT , obj client.Object ) {
87- t .Expect (object .GetStatusLastHandledReconcileAt (obj )).To (Equal (" " ))
88- },
89- },
90- {
91- name : "reconcile annotation with special characters" ,
92- beforeFunc : func (obj client.Object ) {
93- obj .SetAnnotations (map [string ]string {
94- meta .ReconcileRequestAnnotation : "2024-01-15T10:30:00Z" ,
95- })
96- },
97- afterFunc : func (t * WithT , obj client.Object ) {
98- t .Expect (object .GetStatusLastHandledReconcileAt (obj )).To (Equal ("2024-01-15T10:30:00Z" ))
99- },
100- },
101- {
102- name : "reconcile annotation with very long value" ,
103- beforeFunc : func (obj client.Object ) {
104- longValue := strings .Repeat ("a" , 1000 )
105- obj .SetAnnotations (map [string ]string {
106- meta .ReconcileRequestAnnotation : longValue ,
107- })
108- },
109- afterFunc : func (t * WithT , obj client.Object ) {
110- longValue := strings .Repeat ("a" , 1000 )
111- t .Expect (object .GetStatusLastHandledReconcileAt (obj )).To (Equal (longValue ))
112- },
113- },
114- {
115- name : "reconcile annotation mixed with other annotations" ,
116- beforeFunc : func (obj client.Object ) {
117- obj .SetAnnotations (map [string ]string {
118- "some.other/annotation" : "other-value" ,
119- meta .ReconcileRequestAnnotation : "mixed-test" ,
120- "another/annotation" : "another-value" ,
121- })
122- },
123- afterFunc : func (t * WithT , obj client.Object ) {
124- t .Expect (object .GetStatusLastHandledReconcileAt (obj )).To (Equal ("mixed-test" ))
125- t .Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("some.other/annotation" , "other-value" ))
126- t .Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("another/annotation" , "another-value" ))
88+ t .Expect (obj ).To (HaveStatusLastHandledReconcileAt (" " ))
12789 },
12890 },
12991 {
13092 name : "reconcile annotation overwrites existing status value" ,
13193 beforeFunc : func (obj client.Object ) {
13294 object .SetStatusLastHandledReconcileAt (obj , "old-value" )
133- obj . SetAnnotations ( map [string ]string {
95+ annotations := map [string ]string {
13496 meta .ReconcileRequestAnnotation : "new-value" ,
135- })
136- },
137- afterFunc : func (t * WithT , obj client.Object ) {
138- t .Expect (object .GetStatusLastHandledReconcileAt (obj )).To (Equal ("new-value" ))
139- },
140- },
141- {
142- name : "nil annotations map" ,
143- beforeFunc : func (obj client.Object ) {
144- obj .SetAnnotations (nil )
97+ }
98+ obj .SetAnnotations (annotations )
14599 },
146100 afterFunc : func (t * WithT , obj client.Object ) {
147- t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ( " " ))
101+ t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ( "new-value " ))
148102 },
149103 },
150104 }
151105
152106 for _ , tt := range tests {
153107 t .Run (tt .name , func (t * testing.T ) {
154108 g := NewWithT (t )
109+
155110 obj := & sourcev1.GitRepository {
156111 ObjectMeta : metav1.ObjectMeta {
157112 GenerateName : "test-obj" ,
158113 },
159114 }
115+
160116 if tt .beforeFunc != nil {
161117 tt .beforeFunc (obj )
162118 }
119+
163120 ctx := context .TODO ()
164- // This call may internally trigger logic that sets status based on annotations.
165121 RecordReconcileReq (ctx , record .NewFakeRecorder (32 ), obj , reconcile .ResultEmpty , nil )
122+
166123 if tt .afterFunc != nil {
167124 tt .afterFunc (g , obj )
168125 }
0 commit comments