@@ -7,8 +7,11 @@ import (
77 "testing"
88 "time"
99
10+ certmanagerv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
11+ certmanmetav1 "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
1012 "github.com/kuadrant/policy-machinery/machinery"
1113 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+ "sigs.k8s.io/controller-runtime/pkg/event"
1215
1316 kuadrantv1beta1 "github.com/kuadrant/kuadrant-operator/api/v1beta1"
1417)
@@ -109,3 +112,101 @@ func TestGetKuadrant(t *testing.T) {
109112 })
110113 }
111114}
115+
116+ func TestIssuerStatusChangedPredicate (t * testing.T ) {
117+ ready := certmanagerv1.IssuerStatus {
118+ Conditions : []certmanagerv1.IssuerCondition {{
119+ Type : certmanagerv1 .IssuerConditionReady ,
120+ Status : certmanmetav1 .ConditionTrue ,
121+ }},
122+ }
123+ notReady := certmanagerv1.IssuerStatus {
124+ Conditions : []certmanagerv1.IssuerCondition {{
125+ Type : certmanagerv1 .IssuerConditionReady ,
126+ Status : certmanmetav1 .ConditionFalse ,
127+ }},
128+ }
129+
130+ predicate := issuerStatusChangedPredicate ()
131+
132+ tests := []struct {
133+ name string
134+ old certmanagerv1.IssuerStatus
135+ new certmanagerv1.IssuerStatus
136+ want bool
137+ }{
138+ {
139+ name : "status change triggers reconciliation" ,
140+ old : notReady ,
141+ new : ready ,
142+ want : true ,
143+ },
144+ {
145+ name : "unchanged status is ignored" ,
146+ old : ready ,
147+ new : ready ,
148+ want : false ,
149+ },
150+ }
151+
152+ for _ , tt := range tests {
153+ t .Run (tt .name , func (t * testing.T ) {
154+ got := predicate .Update (event.TypedUpdateEvent [* certmanagerv1.Issuer ]{
155+ ObjectOld : & certmanagerv1.Issuer {Status : tt .old },
156+ ObjectNew : & certmanagerv1.Issuer {Status : tt .new },
157+ })
158+ if got != tt .want {
159+ t .Fatalf ("issuerStatusChangedPredicate().Update() = %v, want %v" , got , tt .want )
160+ }
161+ })
162+ }
163+ }
164+
165+ func TestClusterIssuerStatusChangedPredicate (t * testing.T ) {
166+ ready := certmanagerv1.IssuerStatus {
167+ Conditions : []certmanagerv1.IssuerCondition {{
168+ Type : certmanagerv1 .IssuerConditionReady ,
169+ Status : certmanmetav1 .ConditionTrue ,
170+ }},
171+ }
172+ notReady := certmanagerv1.IssuerStatus {
173+ Conditions : []certmanagerv1.IssuerCondition {{
174+ Type : certmanagerv1 .IssuerConditionReady ,
175+ Status : certmanmetav1 .ConditionFalse ,
176+ }},
177+ }
178+
179+ predicate := clusterIssuerStatusChangedPredicate ()
180+
181+ tests := []struct {
182+ name string
183+ old certmanagerv1.IssuerStatus
184+ new certmanagerv1.IssuerStatus
185+ want bool
186+ }{
187+ {
188+ name : "status change triggers reconciliation" ,
189+ old : notReady ,
190+ new : ready ,
191+ want : true ,
192+ },
193+ {
194+ name : "unchanged status is ignored" ,
195+ old : ready ,
196+ new : ready ,
197+ want : false ,
198+ },
199+ }
200+
201+ for _ , tt := range tests {
202+ t .Run (tt .name , func (t * testing.T ) {
203+ got := predicate .Update (event.TypedUpdateEvent [* certmanagerv1.ClusterIssuer ]{
204+ ObjectOld : & certmanagerv1.ClusterIssuer {Status : tt .old },
205+ ObjectNew : & certmanagerv1.ClusterIssuer {Status : tt .new },
206+ })
207+ if got != tt .want {
208+ t .Fatalf ("clusterIssuerStatusChangedPredicate().Update() = %v, want %v" , got , tt .want )
209+ }
210+ })
211+ }
212+ }
0 commit comments