@@ -34,6 +34,26 @@ import (
3434 "github.com/fluxcd/source-controller/internal/reconcile"
3535)
3636
37+ package summarize
38+
39+ import (
40+ "context"
41+ "errors"
42+ "strings"
43+ "testing"
44+
45+ . "github.com/onsi/gomega"
46+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
47+ "k8s.io/client-go/tools/record"
48+ "sigs.k8s.io/controller-runtime/pkg/client"
49+
50+ "github.com/fluxcd/pkg/apis/meta"
51+
52+ sourcev1 "github.com/fluxcd/source-controller/api/v1"
53+ "github.com/fluxcd/source-controller/internal/object"
54+ "github.com/fluxcd/source-controller/internal/reconcile"
55+ )
56+
3757func TestRecordReconcileReq (t * testing.T ) {
3858 tests := []struct {
3959 name string
@@ -43,7 +63,7 @@ func TestRecordReconcileReq(t *testing.T) {
4363 {
4464 name : "no reconcile req" ,
4565 afterFunc : func (t * WithT , obj client.Object ) {
46- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("" ))
66+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("" ))
4767 },
4868 },
4969 {
@@ -52,7 +72,7 @@ func TestRecordReconcileReq(t *testing.T) {
5272 object .SetStatusLastHandledReconcileAt (obj , "zzz" )
5373 },
5474 afterFunc : func (t * WithT , obj client.Object ) {
55- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("zzz" ))
75+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("zzz" ))
5676 },
5777 },
5878 {
@@ -64,10 +84,9 @@ func TestRecordReconcileReq(t *testing.T) {
6484 obj .SetAnnotations (annotations )
6585 },
6686 afterFunc : func (t * WithT , obj client.Object ) {
67- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("now" ))
87+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("now" ))
6888 },
6989 },
70- // Additional test cases for bulletproof coverage:
7190 {
7291 name : "empty reconcile annotation value" ,
7392 beforeFunc : func (obj client.Object ) {
@@ -77,7 +96,7 @@ func TestRecordReconcileReq(t *testing.T) {
7796 obj .SetAnnotations (annotations )
7897 },
7998 afterFunc : func (t * WithT , obj client.Object ) {
80- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("" ))
99+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("" ))
81100 },
82101 },
83102 {
@@ -89,7 +108,7 @@ func TestRecordReconcileReq(t *testing.T) {
89108 obj .SetAnnotations (annotations )
90109 },
91110 afterFunc : func (t * WithT , obj client.Object ) {
92- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt (" " ))
111+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal (" " ))
93112 },
94113 },
95114 {
@@ -101,7 +120,7 @@ func TestRecordReconcileReq(t *testing.T) {
101120 obj .SetAnnotations (annotations )
102121 },
103122 afterFunc : func (t * WithT , obj client.Object ) {
104- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("2024-01-15T10:30:00Z" ))
123+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("2024-01-15T10:30:00Z" ))
105124 },
106125 },
107126 {
@@ -115,7 +134,7 @@ func TestRecordReconcileReq(t *testing.T) {
115134 },
116135 afterFunc : func (t * WithT , obj client.Object ) {
117136 longValue := strings .Repeat ("a" , 1000 )
118- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt (longValue ))
137+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal (longValue ))
119138 },
120139 },
121140 {
@@ -129,24 +148,22 @@ func TestRecordReconcileReq(t *testing.T) {
129148 obj .SetAnnotations (annotations )
130149 },
131150 afterFunc : func (t * WithT , obj client.Object ) {
132- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("mixed-test" ))
151+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("mixed-test" ))
133152 t .Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("some.other/annotation" , "other-value" ))
134153 t .Expect (obj .GetAnnotations ()).To (HaveKeyWithValue ("another/annotation" , "another-value" ))
135154 },
136155 },
137156 {
138157 name : "reconcile annotation overwrites existing status value" ,
139158 beforeFunc : func (obj client.Object ) {
140- // Set initial status
141159 object .SetStatusLastHandledReconcileAt (obj , "old-value" )
142- // Then set annotation
143160 annotations := map [string ]string {
144161 meta .ReconcileRequestAnnotation : "new-value" ,
145162 }
146163 obj .SetAnnotations (annotations )
147164 },
148165 afterFunc : func (t * WithT , obj client.Object ) {
149- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("new-value" ))
166+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("new-value" ))
150167 },
151168 },
152169 {
@@ -155,7 +172,7 @@ func TestRecordReconcileReq(t *testing.T) {
155172 obj .SetAnnotations (nil )
156173 },
157174 afterFunc : func (t * WithT , obj client.Object ) {
158- t .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("" ))
175+ t .Expect (object . GetStatusLastHandledReconcileAt ( obj )) .To (Equal ("" ))
159176 },
160177 },
161178 }
@@ -179,26 +196,3 @@ func TestRecordReconcileReq(t *testing.T) {
179196 })
180197 }
181198}
182-
183- func TestRecordReconcileReq_ParameterHandling (t * testing.T ) {
184- g := NewWithT (t )
185- obj := & sourcev1.GitRepository {
186- ObjectMeta : metav1.ObjectMeta {
187- GenerateName : "test-obj" ,
188- Annotations : map [string ]string {
189- meta .ReconcileRequestAnnotation : "param-test" ,
190- },
191- },
192- }
193-
194- ctx := context .TODO ()
195-
196- RecordReconcileReq (ctx , nil , obj , reconcile .ResultEmpty , nil )
197- g .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("param-test" ))
198-
199- RecordReconcileReq (ctx , record .NewFakeRecorder (32 ), obj , reconcile.Result {Requeue : true }, nil )
200- g .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("param-test" ))
201-
202- RecordReconcileReq (ctx , record .NewFakeRecorder (32 ), obj , reconcile .ResultEmpty , errors .New ("test error" ))
203- g .Expect (obj ).To (HaveStatusLastHandledReconcileAt ("param-test" ))
204- }
0 commit comments