Skip to content

Commit 0d248e2

Browse files
committed
chore: move fakeValidator from individual file into Validator_test.go
Signed-off-by: STRRL <[email protected]>
1 parent 8770b4d commit 0d248e2

File tree

2 files changed

+46
-68
lines changed

2 files changed

+46
-68
lines changed

pkg/webhook/admission/fake_validator_test.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

pkg/webhook/admission/validator_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,3 +443,49 @@ var _ = Describe("validatingHandler", func() {
443443
PIt("should return 400 in response when delete fails on decode", func() {})
444444

445445
})
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

Comments
 (0)