@@ -44,16 +44,13 @@ var _ = Describe("Handler", func() {
4444 raw , err := json .Marshal (pod )
4545 Ω (err ).ShouldNot (HaveOccurred ())
4646
47- h := handler {
48- Handler : & MutateFunc {
49- Func : func (_ context.Context , _ admission.Request , obj runtime.Object ) admission.Response {
50- pod := obj .(* corev1.Pod )
51- pod .Name = "bar"
52- return admission .Allowed ("" )
53- },
47+ h := withMutationHandler (& MutateFunc {
48+ Func : func (_ context.Context , _ admission.Request , obj runtime.Object ) admission.Response {
49+ pod := obj .(* corev1.Pod )
50+ pod .Name = "bar"
51+ return admission .Allowed ("" )
5452 },
55- Object : & corev1.Pod {},
56- }
53+ }, & corev1.Pod {})
5754 err = h .InjectDecoder (decoder )
5855 Ω (err ).ShouldNot (HaveOccurred ())
5956 result := h .Handle (context .TODO (), admission.Request {
@@ -79,21 +76,19 @@ var _ = Describe("Handler", func() {
7976 raw , err := json .Marshal (pod )
8077 Ω (err ).ShouldNot (HaveOccurred ())
8178
82- h := handler {
83- Handler : & MutateFunc {
84- Func : func (_ context.Context , _ admission.Request , obj runtime.Object ) admission.Response {
85- pod := obj .(* corev1.Pod )
86- pod .Name = "bar"
87- return admission.Response {
88- AdmissionResponse : admissionv1.AdmissionResponse {
89- Allowed : true ,
90- },
91- Patches : []jsonpatch.JsonPatchOperation {},
92- }
93- },
79+ h := withMutationHandler (& MutateFunc {
80+ Func : func (_ context.Context , _ admission.Request , obj runtime.Object ) admission.Response {
81+ pod := obj .(* corev1.Pod )
82+ pod .Name = "bar"
83+ return admission.Response {
84+ AdmissionResponse : admissionv1.AdmissionResponse {
85+ Allowed : true ,
86+ },
87+ Patches : []jsonpatch.JsonPatchOperation {},
88+ }
9489 },
95- Object : & corev1.Pod {},
96- }
90+ }, & corev1.Pod {})
91+
9792 err = h .InjectDecoder (decoder )
9893 Ω (err ).ShouldNot (HaveOccurred ())
9994 result := h .Handle (context .TODO (), admission.Request {
@@ -117,20 +112,18 @@ var _ = Describe("Handler", func() {
117112 raw , err := json .Marshal (pod )
118113 Ω (err ).ShouldNot (HaveOccurred ())
119114
120- h := handler {
121- Handler : & ValidateFuncs {
122- CreateFunc : func (_ context.Context , _ admission.Request , _ runtime.Object ) admission.Response {
123- return admission .Allowed ("" )
124- },
125- UpdateFunc : func (_ context.Context , _ admission.Request , _ runtime.Object , _ runtime.Object ) admission.Response {
126- return admission .Denied ("" )
127- },
128- DeleteFunc : func (_ context.Context , _ admission.Request , _ runtime.Object ) admission.Response {
129- return admission .Denied ("" )
130- },
115+ h := withValidationHandler (& ValidateFuncs {
116+ CreateFunc : func (_ context.Context , _ admission.Request , _ runtime.Object ) admission.Response {
117+ return admission .Allowed ("" )
131118 },
132- Object : & corev1.Pod {},
133- }
119+ UpdateFunc : func (_ context.Context , _ admission.Request , _ runtime.Object , _ runtime.Object ) admission.Response {
120+ return admission .Denied ("" )
121+ },
122+ DeleteFunc : func (_ context.Context , _ admission.Request , _ runtime.Object ) admission.Response {
123+ return admission .Denied ("" )
124+ },
125+ }, & corev1.Pod {})
126+
134127 err = h .InjectDecoder (decoder )
135128 Ω (err ).ShouldNot (HaveOccurred ())
136129
@@ -176,15 +169,13 @@ var _ = Describe("Handler", func() {
176169 raw , err := json .Marshal (pod )
177170 Ω (err ).ShouldNot (HaveOccurred ())
178171
179- h := handler {
180- Handler : & MutateFunc {
181- Func : func (_ context.Context , request admission.Request , object runtime.Object ) admission.Response {
182- Ω (object ).Should (Equal (pod ))
183- return admission .Allowed ("" )
184- },
172+ h := withMutationHandler (& MutateFunc {
173+ Func : func (_ context.Context , request admission.Request , object runtime.Object ) admission.Response {
174+ Ω (object ).Should (Equal (pod ))
175+ return admission .Allowed ("" )
185176 },
186- Object : & corev1.Pod {},
187- }
177+ }, & corev1.Pod {})
178+
188179 err = h .InjectDecoder (decoder )
189180 Ω (err ).ShouldNot (HaveOccurred ())
190181
@@ -210,14 +201,11 @@ var _ = Describe("Handler", func() {
210201 Ω (result .Allowed ).Should (BeTrue ())
211202 })
212203 It ("should not decode invalid object" , func () {
213- h := handler {
214- Handler : & MutateFunc {
215- Func : func (_ context.Context , _ admission.Request , _ runtime.Object ) admission.Response {
216- return admission .Allowed ("" )
217- },
204+ h := withMutationHandler (& MutateFunc {
205+ Func : func (_ context.Context , _ admission.Request , _ runtime.Object ) admission.Response {
206+ return admission .Allowed ("" )
218207 },
219- Object : & corev1.Pod {},
220- }
208+ }, & corev1.Pod {})
221209 err := h .InjectDecoder (decoder )
222210 Ω (err ).ShouldNot (HaveOccurred ())
223211
@@ -249,12 +237,12 @@ var _ = Describe("Handler", func() {
249237 })
250238 It ("should pass decoder to validating webhook" , func () {
251239 webhook := ValidatingWebhook {}
252- Ω ((& handler {Handler : & webhook }).InjectDecoder (decoder )).ShouldNot (HaveOccurred ())
240+ Ω ((& handler {injector : & webhook }).InjectDecoder (decoder )).ShouldNot (HaveOccurred ())
253241 Ω (webhook .Decoder ).Should (Equal (decoder ))
254242 })
255243 It ("should pass decoder to mutating webhook" , func () {
256244 webhook := MutatingWebhook {}
257- Ω ((& handler {Handler : & webhook }).InjectDecoder (decoder )).ShouldNot (HaveOccurred ())
245+ Ω ((& handler {injector : & webhook }).InjectDecoder (decoder )).ShouldNot (HaveOccurred ())
258246 Ω (webhook .Decoder ).Should (Equal (decoder ))
259247 })
260248 It ("should never fail if handler not set" , func () {
@@ -270,12 +258,12 @@ var _ = Describe("Handler", func() {
270258 })
271259 It ("should pass client to validating webhook" , func () {
272260 webhook := ValidatingWebhook {}
273- Ω ((& handler {Handler : & webhook }).InjectClient (client )).ShouldNot (HaveOccurred ())
261+ Ω ((& handler {injector : & webhook }).InjectClient (client )).ShouldNot (HaveOccurred ())
274262 Ω (webhook .Client ).Should (Equal (client ))
275263 })
276264 It ("should pass client to mutating webhook" , func () {
277265 webhook := MutatingWebhook {}
278- Ω ((& handler {Handler : & webhook }).InjectClient (client )).ShouldNot (HaveOccurred ())
266+ Ω ((& handler {injector : & webhook }).InjectClient (client )).ShouldNot (HaveOccurred ())
279267 Ω (webhook .Client ).Should (Equal (client ))
280268 })
281269 It ("should never fail if handler not set" , func () {
0 commit comments