@@ -165,6 +165,49 @@ func TestShouldRolloutAfter(t *testing.T) {
165
165
})
166
166
}
167
167
168
+ func TestShouldRolloutIfCertificatesExpireWithinMinutes (t * testing.T ) {
169
+ t .Run ("if expiry time is nil it should return false" , func (t * testing.T ) {
170
+ g := NewWithT (t )
171
+ m := & clusterv1.Machine {}
172
+ g .Expect (collections .ShouldRolloutIfCertificatesExpireWithinMinutes (nil )(m )).To (BeFalse ())
173
+ })
174
+ t .Run ("if machine is nil it should return false" , func (t * testing.T ) {
175
+ g := NewWithT (t )
176
+ g .Expect (collections .ShouldRolloutIfCertificatesExpireWithinMinutes (pointer .Int32 (10 ))(nil )).To (BeFalse ())
177
+ })
178
+ t .Run ("if the machine certificate expiry infromation is not available it should return false" , func (t * testing.T ) {
179
+ g := NewWithT (t )
180
+ m := & clusterv1.Machine {}
181
+ g .Expect (collections .ShouldRolloutIfCertificatesExpireWithinMinutes (pointer .Int32 (10 ))(m )).To (BeFalse ())
182
+ })
183
+ t .Run ("if the machine certificates are not going to expiry within the expiry time it should return false" , func (t * testing.T ) {
184
+ g := NewWithT (t )
185
+ // TODO: adjust this later after the API is finalized.
186
+ // Might have to change this to days instead of minutes.
187
+ expiry := pointer .Int32 (10 )
188
+ certificateExpiryTime := time .Now ().Add (60 * time .Minute ) // certificates will expire in 60 minutes from 'now'.
189
+ m := & clusterv1.Machine {
190
+ Status : clusterv1.MachineStatus {
191
+ CertificatesExpiryDate : & metav1.Time {Time : certificateExpiryTime },
192
+ },
193
+ }
194
+ g .Expect (collections .ShouldRolloutIfCertificatesExpireWithinMinutes (expiry )(m )).To (BeFalse ())
195
+ })
196
+ t .Run ("if machine certificates will expire within the expiry time then it should return true" , func (t * testing.T ) {
197
+ g := NewWithT (t )
198
+ // TODO: adjust this later after the API is finalized.
199
+ // Might have to change this to days instead of minutes.
200
+ expiry := pointer .Int32 (60 )
201
+ certificateExpiryTime := time .Now ().Add (10 * time .Minute ) // certificates will expire in 10 minutes from 'now'.
202
+ m := & clusterv1.Machine {
203
+ Status : clusterv1.MachineStatus {
204
+ CertificatesExpiryDate : & metav1.Time {Time : certificateExpiryTime },
205
+ },
206
+ }
207
+ g .Expect (collections .ShouldRolloutIfCertificatesExpireWithinMinutes (expiry )(m )).To (BeTrue ())
208
+ })
209
+ }
210
+
168
211
func TestHashAnnotationKey (t * testing.T ) {
169
212
t .Run ("machine with specified annotation returns true" , func (t * testing.T ) {
170
213
g := NewWithT (t )
0 commit comments