@@ -443,3 +443,49 @@ var _ = Describe("validatingHandler", func() {
443
443
PIt ("should return 400 in response when delete fails on decode" , func () {})
444
444
445
445
})
446
+
447
+ // fakeValidator provides fake validating webhook functionality for testing
448
+ // It implements the admission.Validator interface and
449
+ // rejects all requests with the same configured error
450
+ // or passes if ErrorToReturn is nil.
451
+ // And it would always return configured warning messages WarningsToReturn.
452
+ type fakeValidator struct {
453
+ // ErrorToReturn is the error for which the fakeValidator rejects all requests
454
+ ErrorToReturn error `json:"errorToReturn,omitempty"`
455
+ // GVKToReturn is the GroupVersionKind that the webhook operates on
456
+ GVKToReturn schema.GroupVersionKind
457
+ // WarningsToReturn is the warnings for fakeValidator returns to all requests
458
+ WarningsToReturn []string
459
+ }
460
+
461
+ func (v * fakeValidator ) ValidateCreate () (warnings Warnings , err error ) {
462
+ return v .WarningsToReturn , v .ErrorToReturn
463
+ }
464
+
465
+ func (v * fakeValidator ) ValidateUpdate (old runtime.Object ) (warnings Warnings , err error ) {
466
+ return v .WarningsToReturn , v .ErrorToReturn
467
+ }
468
+
469
+ func (v * fakeValidator ) ValidateDelete () (warnings Warnings , err error ) {
470
+ return v .WarningsToReturn , v .ErrorToReturn
471
+ }
472
+
473
+ func (v * fakeValidator ) SetGroupVersionKind (gvk schema.GroupVersionKind ) {
474
+ v .GVKToReturn = gvk
475
+ }
476
+
477
+ func (v * fakeValidator ) GroupVersionKind () schema.GroupVersionKind {
478
+ return v .GVKToReturn
479
+ }
480
+
481
+ func (v * fakeValidator ) GetObjectKind () schema.ObjectKind {
482
+ return v
483
+ }
484
+
485
+ func (v * fakeValidator ) DeepCopyObject () runtime.Object {
486
+ return & fakeValidator {
487
+ ErrorToReturn : v .ErrorToReturn ,
488
+ GVKToReturn : v .GVKToReturn ,
489
+ WarningsToReturn : v .WarningsToReturn ,
490
+ }
491
+ }
0 commit comments