@@ -18,233 +18,206 @@ import (
18
18
19
19
var _ = Describe ("validatingHandler" , func () {
20
20
Describe ("Handle" , func () {
21
+ It ("should return 200 in response when create succeeds" , func () {
21
22
22
- When ("create succeeds" , func () {
23
- It ("should return allowed in response" , func () {
23
+ handler := createSucceedingValidatingHandler ()
24
24
25
- handler := createSucceedingValidatingHandler ()
26
-
27
- response := handler .Handle (context .TODO (), Request {
28
- AdmissionRequest : v1beta1.AdmissionRequest {
29
- Operation : v1beta1 .Create ,
30
- Object : runtime.RawExtension {
31
- Raw : []byte ("{}" ),
32
- Object : handler .validator ,
33
- },
25
+ response := handler .Handle (context .TODO (), Request {
26
+ AdmissionRequest : v1beta1.AdmissionRequest {
27
+ Operation : v1beta1 .Create ,
28
+ Object : runtime.RawExtension {
29
+ Raw : []byte ("{}" ),
30
+ Object : handler .validator ,
34
31
},
35
- })
36
- Expect (response .Allowed ).Should (BeTrue ())
37
- Expect (response .Result .Code ).Should (Equal (int32 (http .StatusOK )))
32
+ },
38
33
})
34
+ Expect (response .Allowed ).Should (BeTrue ())
35
+ Expect (response .Result .Code ).Should (Equal (int32 (http .StatusOK )))
39
36
})
40
37
41
- When ("create fails on decode" , func () {
42
- It ("should return 400 in response" , func () {
43
- //TODO
44
- })
38
+ It ("should return 400 in response when create fails on decode" , func () {
39
+ //TODO
45
40
})
46
41
47
- When ("ValidateCreate returns APIStatus error" , func () {
48
- It ("should return Status.Code and embed the Status object from APIStatus in the response" , func () {
42
+ It ("should return response built with the Status object when ValidateCreate returns APIStatus error" , func () {
49
43
50
- handler , expectedError := createValidatingHandlerWhichReturnsStatusError ()
44
+ handler , expectedError := createValidatingHandlerWhichReturnsStatusError ()
51
45
52
- response := handler .Handle (context .TODO (), Request {
53
- AdmissionRequest : v1beta1.AdmissionRequest {
54
- Operation : v1beta1 .Create ,
55
- Object : runtime.RawExtension {
56
- Raw : []byte ("{}" ),
57
- Object : handler .validator ,
58
- },
46
+ response := handler .Handle (context .TODO (), Request {
47
+ AdmissionRequest : v1beta1.AdmissionRequest {
48
+ Operation : v1beta1 .Create ,
49
+ Object : runtime.RawExtension {
50
+ Raw : []byte ("{}" ),
51
+ Object : handler .validator ,
59
52
},
60
- })
61
- Expect (response .Allowed ).Should (BeFalse ())
53
+ },
54
+ })
55
+ Expect (response .Allowed ).Should (BeFalse ())
62
56
63
- apiStatus , ok := expectedError .(apierrs.APIStatus )
64
- Expect (ok ).Should (BeTrue ())
65
- Expect (response .Result .Code ).Should (Equal (apiStatus .Status ().Code ))
66
- Expect (* response .Result ).Should (Equal (apiStatus .Status ()))
57
+ apiStatus , ok := expectedError .(apierrs.APIStatus )
58
+ Expect (ok ).Should (BeTrue ())
59
+ Expect (response .Result .Code ).Should (Equal (apiStatus .Status ().Code ))
60
+ Expect (* response .Result ).Should (Equal (apiStatus .Status ()))
67
61
68
- })
69
62
})
70
63
71
- When ("ValidateCreate returns any error" , func () {
72
- It ("should return 403 and embed the error message in a generated Status object in the response" , func () {
64
+ It ("should return 403 response when ValidateCreate returns non-APIStatus error" , func () {
73
65
74
- handler , expectedError := createValidatingHandlerWhichReturnsRegularError ()
66
+ handler , expectedError := createValidatingHandlerWhichReturnsRegularError ()
75
67
76
- response := handler .Handle (context .TODO (), Request {
77
- AdmissionRequest : v1beta1.AdmissionRequest {
78
- Operation : v1beta1 .Create ,
79
- Object : runtime.RawExtension {
80
- Raw : []byte ("{}" ),
81
- Object : handler .validator ,
82
- },
68
+ response := handler .Handle (context .TODO (), Request {
69
+ AdmissionRequest : v1beta1.AdmissionRequest {
70
+ Operation : v1beta1 .Create ,
71
+ Object : runtime.RawExtension {
72
+ Raw : []byte ("{}" ),
73
+ Object : handler .validator ,
83
74
},
84
- })
85
- Expect (response .Allowed ).Should (BeFalse ())
86
- Expect (response .Result .Code ).Should (Equal (int32 (http .StatusForbidden )))
87
- Expect (string (response .Result .Reason )).Should (Equal (expectedError .Error ()))
88
-
75
+ },
89
76
})
77
+ Expect (response .Allowed ).Should (BeFalse ())
78
+ Expect (response .Result .Code ).Should (Equal (int32 (http .StatusForbidden )))
79
+ Expect (string (response .Result .Reason )).Should (Equal (expectedError .Error ()))
80
+
90
81
})
91
82
92
- When ("update succeeds" , func () {
93
- It ("should return allowed in response" , func () {
94
-
95
- handler := createSucceedingValidatingHandler ()
96
-
97
- response := handler .Handle (context .TODO (), Request {
98
- AdmissionRequest : v1beta1.AdmissionRequest {
99
- Operation : v1beta1 .Update ,
100
- Object : runtime.RawExtension {
101
- Raw : []byte ("{}" ),
102
- Object : handler .validator ,
103
- },
104
- OldObject : runtime.RawExtension {
105
- Raw : []byte ("{}" ),
106
- Object : handler .validator ,
107
- },
83
+ It ("should return 200 in response when update succeeds" , func () {
84
+
85
+ handler := createSucceedingValidatingHandler ()
86
+
87
+ response := handler .Handle (context .TODO (), Request {
88
+ AdmissionRequest : v1beta1.AdmissionRequest {
89
+ Operation : v1beta1 .Update ,
90
+ Object : runtime.RawExtension {
91
+ Raw : []byte ("{}" ),
92
+ Object : handler .validator ,
93
+ },
94
+ OldObject : runtime.RawExtension {
95
+ Raw : []byte ("{}" ),
96
+ Object : handler .validator ,
108
97
},
109
- })
110
- Expect (response .Allowed ).Should (BeTrue ())
111
- Expect (response .Result .Code ).Should (Equal (int32 (http .StatusOK )))
98
+ },
112
99
})
100
+ Expect (response .Allowed ).Should (BeTrue ())
101
+ Expect (response .Result .Code ).Should (Equal (int32 (http .StatusOK )))
113
102
})
114
103
115
- When ("update fails on decoding new object" , func () {
116
- It ("should return 400 in response" , func () {
117
- //TODO
118
- })
104
+ It ("should return 400 in response when update fails on decoding new object" , func () {
105
+ //TODO
119
106
})
120
107
121
- When ("update fails on decoding old object" , func () {
122
- It ("should return 400 in response" , func () {
123
- //TODO
124
- })
108
+ It ("should return 400 in response when update fails on decoding old object" , func () {
109
+ //TODO
125
110
})
126
111
127
- When ("ValidateUpdate returns APIStatus error" , func () {
128
- It ("should return Status.Code and embed the Status object from APIStatus in the response" , func () {
129
-
130
- handler , expectedError := createValidatingHandlerWhichReturnsStatusError ()
131
-
132
- response := handler .Handle (context .TODO (), Request {
133
- AdmissionRequest : v1beta1.AdmissionRequest {
134
- Operation : v1beta1 .Update ,
135
- Object : runtime.RawExtension {
136
- Raw : []byte ("{}" ),
137
- Object : handler .validator ,
138
- },
139
- OldObject : runtime.RawExtension {
140
- Raw : []byte ("{}" ),
141
- Object : handler .validator ,
142
- },
143
- },
144
- })
145
- Expect (response .Allowed ).Should (BeFalse ())
112
+ It ("should return response built with the Status object when ValidateUpdate returns APIStatus error" , func () {
146
113
147
- apiStatus , ok := expectedError .(apierrs.APIStatus )
148
- Expect (ok ).Should (BeTrue ())
149
- Expect (response .Result .Code ).Should (Equal (apiStatus .Status ().Code ))
150
- Expect (* response .Result ).Should (Equal (apiStatus .Status ()))
114
+ handler , expectedError := createValidatingHandlerWhichReturnsStatusError ()
151
115
116
+ response := handler .Handle (context .TODO (), Request {
117
+ AdmissionRequest : v1beta1.AdmissionRequest {
118
+ Operation : v1beta1 .Update ,
119
+ Object : runtime.RawExtension {
120
+ Raw : []byte ("{}" ),
121
+ Object : handler .validator ,
122
+ },
123
+ OldObject : runtime.RawExtension {
124
+ Raw : []byte ("{}" ),
125
+ Object : handler .validator ,
126
+ },
127
+ },
152
128
})
129
+ Expect (response .Allowed ).Should (BeFalse ())
130
+
131
+ apiStatus , ok := expectedError .(apierrs.APIStatus )
132
+ Expect (ok ).Should (BeTrue ())
133
+ Expect (response .Result .Code ).Should (Equal (apiStatus .Status ().Code ))
134
+ Expect (* response .Result ).Should (Equal (apiStatus .Status ()))
135
+
153
136
})
154
137
155
- When ("ValidateUpdate returns any error" , func () {
156
- It ("should return 403 and embed the error message in a generated Status object in the response" , func () {
157
-
158
- handler , expectedError := createValidatingHandlerWhichReturnsRegularError ()
159
-
160
- response := handler .Handle (context .TODO (), Request {
161
- AdmissionRequest : v1beta1.AdmissionRequest {
162
- Operation : v1beta1 .Update ,
163
- Object : runtime.RawExtension {
164
- Raw : []byte ("{}" ),
165
- Object : handler .validator ,
166
- },
167
- OldObject : runtime.RawExtension {
168
- Raw : []byte ("{}" ),
169
- Object : handler .validator ,
170
- },
171
- },
172
- })
173
- Expect (response .Allowed ).Should (BeFalse ())
174
- Expect (response .Result .Code ).Should (Equal (int32 (http .StatusForbidden )))
175
- Expect (string (response .Result .Reason )).Should (Equal (expectedError .Error ()))
138
+ It ("should return 403 response when ValidateUpdate returns non-APIStatus error" , func () {
176
139
140
+ handler , expectedError := createValidatingHandlerWhichReturnsRegularError ()
141
+
142
+ response := handler .Handle (context .TODO (), Request {
143
+ AdmissionRequest : v1beta1.AdmissionRequest {
144
+ Operation : v1beta1 .Update ,
145
+ Object : runtime.RawExtension {
146
+ Raw : []byte ("{}" ),
147
+ Object : handler .validator ,
148
+ },
149
+ OldObject : runtime.RawExtension {
150
+ Raw : []byte ("{}" ),
151
+ Object : handler .validator ,
152
+ },
153
+ },
177
154
})
155
+ Expect (response .Allowed ).Should (BeFalse ())
156
+ Expect (response .Result .Code ).Should (Equal (int32 (http .StatusForbidden )))
157
+ Expect (string (response .Result .Reason )).Should (Equal (expectedError .Error ()))
158
+
178
159
})
179
160
180
- When ("delete succeeds" , func () {
181
- It ("should return allowed in response" , func () {
161
+ It ("should return 200 in response when delete succeeds" , func () {
182
162
183
- handler := createSucceedingValidatingHandler ()
163
+ handler := createSucceedingValidatingHandler ()
184
164
185
- response := handler .Handle (context .TODO (), Request {
186
- AdmissionRequest : v1beta1.AdmissionRequest {
187
- Operation : v1beta1 .Delete ,
188
- OldObject : runtime.RawExtension {
189
- Raw : []byte ("{}" ),
190
- Object : handler .validator ,
191
- },
165
+ response := handler .Handle (context .TODO (), Request {
166
+ AdmissionRequest : v1beta1.AdmissionRequest {
167
+ Operation : v1beta1 .Delete ,
168
+ OldObject : runtime.RawExtension {
169
+ Raw : []byte ("{}" ),
170
+ Object : handler .validator ,
192
171
},
193
- })
194
- Expect (response .Allowed ).Should (BeTrue ())
195
- Expect (response .Result .Code ).Should (Equal (int32 (http .StatusOK )))
172
+ },
196
173
})
174
+ Expect (response .Allowed ).Should (BeTrue ())
175
+ Expect (response .Result .Code ).Should (Equal (int32 (http .StatusOK )))
197
176
})
198
177
199
- When ("delete fails on decode" , func () {
200
- It ("should return 400 in response" , func () {
201
- //TODO
202
- })
178
+ It ("should return 400 in response when delete fails on decode" , func () {
179
+ //TODO
203
180
})
204
181
205
- When ("ValidateDelete returns APIStatus error" , func () {
206
- It ("should return Status.Code and embed the Status object from APIStatus in the response" , func () {
182
+ It ("should return response built with the Status object when ValidateDelete returns APIStatus error" , func () {
207
183
208
- handler , expectedError := createValidatingHandlerWhichReturnsStatusError ()
184
+ handler , expectedError := createValidatingHandlerWhichReturnsStatusError ()
209
185
210
- response := handler .Handle (context .TODO (), Request {
211
- AdmissionRequest : v1beta1.AdmissionRequest {
212
- Operation : v1beta1 .Delete ,
213
- OldObject : runtime.RawExtension {
214
- Raw : []byte ("{}" ),
215
- Object : handler .validator ,
216
- },
186
+ response := handler .Handle (context .TODO (), Request {
187
+ AdmissionRequest : v1beta1.AdmissionRequest {
188
+ Operation : v1beta1 .Delete ,
189
+ OldObject : runtime.RawExtension {
190
+ Raw : []byte ("{}" ),
191
+ Object : handler .validator ,
217
192
},
218
- })
219
- Expect (response .Allowed ).Should (BeFalse ())
193
+ },
194
+ })
195
+ Expect (response .Allowed ).Should (BeFalse ())
220
196
221
- apiStatus , ok := expectedError .(apierrs.APIStatus )
222
- Expect (ok ).Should (BeTrue ())
223
- Expect (response .Result .Code ).Should (Equal (apiStatus .Status ().Code ))
224
- Expect (* response .Result ).Should (Equal (apiStatus .Status ()))
197
+ apiStatus , ok := expectedError .(apierrs.APIStatus )
198
+ Expect (ok ).Should (BeTrue ())
199
+ Expect (response .Result .Code ).Should (Equal (apiStatus .Status ().Code ))
200
+ Expect (* response .Result ).Should (Equal (apiStatus .Status ()))
225
201
226
- })
227
202
})
228
203
229
- When ("ValidateDelete returns any error" , func () {
230
- It ("should return 403 and embed the error message in a generated Status object in the response" , func () {
204
+ It ("should return 403 response when ValidateDelete returns non-APIStatus error" , func () {
231
205
232
- handler , expectedError := createValidatingHandlerWhichReturnsRegularError ()
206
+ handler , expectedError := createValidatingHandlerWhichReturnsRegularError ()
233
207
234
- response := handler .Handle (context .TODO (), Request {
235
- AdmissionRequest : v1beta1.AdmissionRequest {
236
- Operation : v1beta1 .Delete ,
237
- OldObject : runtime.RawExtension {
238
- Raw : []byte ("{}" ),
239
- Object : handler .validator ,
240
- },
208
+ response := handler .Handle (context .TODO (), Request {
209
+ AdmissionRequest : v1beta1.AdmissionRequest {
210
+ Operation : v1beta1 .Delete ,
211
+ OldObject : runtime.RawExtension {
212
+ Raw : []byte ("{}" ),
213
+ Object : handler .validator ,
241
214
},
242
- })
243
- Expect (response .Allowed ).Should (BeFalse ())
244
- Expect (response .Result .Code ).Should (Equal (int32 (http .StatusForbidden )))
245
- Expect (string (response .Result .Reason )).Should (Equal (expectedError .Error ()))
246
-
215
+ },
247
216
})
217
+ Expect (response .Allowed ).Should (BeFalse ())
218
+ Expect (response .Result .Code ).Should (Equal (int32 (http .StatusForbidden )))
219
+ Expect (string (response .Result .Reason )).Should (Equal (expectedError .Error ()))
220
+
248
221
})
249
222
})
250
223
})
0 commit comments