@@ -205,7 +205,7 @@ const webhookTestCreateDefaultingReplaceFragment = `It("Should apply defaults wh
205
205
obj.Spec.FailedJobsHistoryLimit = nil // This should default to 1
206
206
207
207
By("calling the Default method to apply defaults")
208
- defaulter.Default(ctx, obj)
208
+ _ = defaulter.Default(ctx, obj)
209
209
210
210
By("checking that the default values are set")
211
211
Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.AllowConcurrent), "Expected ConcurrencyPolicy to default to AllowConcurrent")
@@ -225,7 +225,7 @@ const webhookTestCreateDefaultingReplaceFragment = `It("Should apply defaults wh
225
225
*obj.Spec.FailedJobsHistoryLimit = 2
226
226
227
227
By("calling the Default method to apply defaults")
228
- defaulter.Default(ctx, obj)
228
+ _ = defaulter.Default(ctx, obj)
229
229
230
230
By("checking that the fields were not overwritten")
231
231
Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.ForbidConcurrent), "Expected ConcurrencyPolicy to retain its set value")
@@ -263,7 +263,7 @@ const webhookTestingValidatingExampleFragment = `It("Should deny creation if the
263
263
})
264
264
265
265
It("Should admit creation if the name is valid", func() {
266
- obj.ObjectMeta.Name = "valid-cronjob-name"
266
+ obj.ObjectMeta.Name = validCronJobName
267
267
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
268
268
"Expected name validation to pass for a valid name")
269
269
})
@@ -276,14 +276,14 @@ const webhookTestingValidatingExampleFragment = `It("Should deny creation if the
276
276
})
277
277
278
278
It("Should admit creation if the schedule is valid", func() {
279
- obj.Spec.Schedule = "*/5 * * * *"
279
+ obj.Spec.Schedule = schedule
280
280
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
281
281
"Expected spec validation to pass for a valid schedule")
282
282
})
283
283
284
284
It("Should deny update if both name and spec are invalid", func() {
285
- oldObj.ObjectMeta.Name = "valid-cronjob-name"
286
- oldObj.Spec.Schedule = "*/5 * * * *"
285
+ oldObj.ObjectMeta.Name = validCronJobName
286
+ oldObj.Spec.Schedule = schedule
287
287
288
288
By("simulating an update")
289
289
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
@@ -295,8 +295,8 @@ const webhookTestingValidatingExampleFragment = `It("Should deny creation if the
295
295
})
296
296
297
297
It("Should admit update if both name and spec are valid", func() {
298
- oldObj.ObjectMeta.Name = "valid-cronjob-name"
299
- oldObj.Spec.Schedule = "*/5 * * * *"
298
+ oldObj.ObjectMeta.Name = validCronJobName
299
+ oldObj.Spec.Schedule = schedule
300
300
301
301
By("simulating an update")
302
302
obj.ObjectMeta.Name = "valid-cronjob-name-updated"
@@ -307,6 +307,21 @@ const webhookTestingValidatingExampleFragment = `It("Should deny creation if the
307
307
"Expected validation to pass for a valid update")
308
308
})`
309
309
310
+ const webhookTestsVars = `var (
311
+ obj *batchv1.CronJob
312
+ oldObj *batchv1.CronJob
313
+ validator CronJobCustomValidator
314
+ defaulter CronJobCustomDefaulter
315
+ )`
316
+ const webhookTestsConstants = ` var (
317
+ obj *batchv1.CronJob
318
+ oldObj *batchv1.CronJob
319
+ validator CronJobCustomValidator
320
+ defaulter CronJobCustomDefaulter
321
+ )
322
+
323
+ const validCronJobName = "valid-cronjob-name"
324
+ const schedule = "*/5 * * * *"`
310
325
const webhookTestsBeforeEachOriginal = `obj = &batchv1.CronJob{}
311
326
oldObj = &batchv1.CronJob{}
312
327
validator = CronJobCustomValidator{}
@@ -319,7 +334,7 @@ const webhookTestsBeforeEachOriginal = `obj = &batchv1.CronJob{}
319
334
320
335
const webhookTestsBeforeEachChanged = `obj = &batchv1.CronJob{
321
336
Spec: batchv1.CronJobSpec{
322
- Schedule: "*/5 * * * *" ,
337
+ Schedule: schedule ,
323
338
ConcurrencyPolicy: batchv1.AllowConcurrent,
324
339
SuccessfulJobsHistoryLimit: new(int32),
325
340
FailedJobsHistoryLimit: new(int32),
@@ -330,7 +345,7 @@ const webhookTestsBeforeEachChanged = `obj = &batchv1.CronJob{
330
345
331
346
oldObj = &batchv1.CronJob{
332
347
Spec: batchv1.CronJobSpec{
333
- Schedule: "*/5 * * * *" ,
348
+ Schedule: schedule ,
334
349
ConcurrencyPolicy: batchv1.AllowConcurrent,
335
350
SuccessfulJobsHistoryLimit: new(int32),
336
351
FailedJobsHistoryLimit: new(int32),
0 commit comments