@@ -146,6 +146,7 @@ func testSyncNamespaceThatIsTerminating(t *testing.T, versions *metav1.APIVersio
146
146
strings .Join ([]string {"get" , "namespaces" , "" }, "-" ),
147
147
strings .Join ([]string {"create" , "namespaces" , "finalize" }, "-" ),
148
148
strings .Join ([]string {"list" , "pods" , "" }, "-" ),
149
+ strings .Join ([]string {"update" , "namespaces" , "status" }, "-" ),
149
150
strings .Join ([]string {"delete" , "namespaces" , "" }, "-" ),
150
151
),
151
152
metadataClientActionSet : metadataClientActionSet ,
@@ -187,68 +188,66 @@ func testSyncNamespaceThatIsTerminating(t *testing.T, versions *metav1.APIVersio
187
188
}
188
189
189
190
for scenario , testInput := range scenarios {
190
- testHandler := & fakeActionHandler {statusCode : 200 }
191
- srv , clientConfig := testServerAndClientConfig (testHandler .ServeHTTP )
192
- defer srv .Close ()
193
-
194
- mockClient := fake .NewSimpleClientset (testInput .testNamespace )
195
- metadataClient , err := metadata .NewForConfig (clientConfig )
196
- if err != nil {
197
- t .Fatal (err )
198
- }
199
-
200
- fn := func () ([]* metav1.APIResourceList , error ) {
201
- return resources , testInput .gvrError
202
- }
203
- d := NewNamespacedResourcesDeleter (mockClient .CoreV1 ().Namespaces (), metadataClient , mockClient .CoreV1 (), fn , v1 .FinalizerKubernetes , true )
204
- if err := d .Delete (testInput .testNamespace .Name ); ! matchErrors (err , testInput .expectErrorOnDelete ) {
205
- t .Errorf ("scenario %s - expected error %q when syncing namespace, got %q, %v" , scenario , testInput .expectErrorOnDelete , err , testInput .expectErrorOnDelete == err )
206
- }
191
+ t .Run (scenario , func (t * testing.T ) {
192
+ testHandler := & fakeActionHandler {statusCode : 200 }
193
+ srv , clientConfig := testServerAndClientConfig (testHandler .ServeHTTP )
194
+ defer srv .Close ()
207
195
208
- // validate traffic from kube client
209
- actionSet := sets .NewString ()
210
- for _ , action := range mockClient .Actions () {
211
- actionSet .Insert (strings .Join ([]string {action .GetVerb (), action .GetResource ().Resource , action .GetSubresource ()}, "-" ))
212
- }
213
- if ! actionSet .Equal (testInput .kubeClientActionSet ) {
214
- t .Errorf ("scenario %s - mock client expected actions:\n %v\n but got:\n %v\n Difference:\n %v" , scenario ,
215
- testInput .kubeClientActionSet , actionSet , testInput .kubeClientActionSet .Difference (actionSet ))
216
- }
196
+ mockClient := fake .NewSimpleClientset (testInput .testNamespace )
197
+ metadataClient , err := metadata .NewForConfig (clientConfig )
198
+ if err != nil {
199
+ t .Fatal (err )
200
+ }
217
201
218
- // validate traffic from metadata client
219
- actionSet = sets .NewString ()
220
- for _ , action := range testHandler .actions {
221
- actionSet .Insert (action .String ())
222
- }
223
- if ! actionSet .Equal (testInput .metadataClientActionSet ) {
224
- t .Errorf ("scenario %s - metadata client expected actions:\n %v\n but got:\n %v\n Difference:\n %v" , scenario ,
225
- testInput .metadataClientActionSet , actionSet , testInput .metadataClientActionSet .Difference (actionSet ))
226
- }
202
+ fn := func () ([]* metav1.APIResourceList , error ) {
203
+ return resources , testInput .gvrError
204
+ }
205
+ d := NewNamespacedResourcesDeleter (mockClient .CoreV1 ().Namespaces (), metadataClient , mockClient .CoreV1 (), fn , v1 .FinalizerKubernetes , true )
206
+ if err := d .Delete (testInput .testNamespace .Name ); ! matchErrors (err , testInput .expectErrorOnDelete ) {
207
+ t .Errorf ("expected error %q when syncing namespace, got %q, %v" , testInput .expectErrorOnDelete , err , testInput .expectErrorOnDelete == err )
208
+ }
227
209
228
- // validate status conditions
229
- if testInput .expectStatus != nil {
230
- obj , err := mockClient .Tracker ().Get (schema.GroupVersionResource {Version : "v1" , Resource : "namespaces" }, testInput .testNamespace .Namespace , testInput .testNamespace .Name )
231
- if err != nil {
232
- t .Errorf ("Unexpected error in getting the namespace: %v" , err )
233
- continue
210
+ // validate traffic from kube client
211
+ actionSet := sets .NewString ()
212
+ for _ , action := range mockClient .Actions () {
213
+ actionSet .Insert (strings .Join ([]string {action .GetVerb (), action .GetResource ().Resource , action .GetSubresource ()}, "-" ))
214
+ }
215
+ if ! actionSet .Equal (testInput .kubeClientActionSet ) {
216
+ t .Errorf ("mock client expected actions:\n %v\n but got:\n %v\n Difference:\n %v" ,
217
+ testInput .kubeClientActionSet , actionSet , testInput .kubeClientActionSet .Difference (actionSet ))
234
218
}
235
- ns , ok := obj .(* v1.Namespace )
236
- if ! ok {
237
- t .Errorf ("Expected a namespace but received %v" , obj )
238
- continue
219
+
220
+ // validate traffic from metadata client
221
+ actionSet = sets .NewString ()
222
+ for _ , action := range testHandler .actions {
223
+ actionSet .Insert (action .String ())
239
224
}
240
- if ns . Status . Phase != testInput .expectStatus . Phase {
241
- t .Errorf ("Expected namespace status phase %v but received %v" , testInput . expectStatus . Phase , ns . Status . Phase )
242
- continue
225
+ if ! actionSet . Equal ( testInput .metadataClientActionSet ) {
226
+ t .Errorf (" metadata client expected actions: \n %v \n but got: \n %v \n Difference: \n %v" ,
227
+ testInput . metadataClientActionSet , actionSet , testInput . metadataClientActionSet . Difference ( actionSet ))
243
228
}
244
- for _ , expCondition := range testInput .expectStatus .Conditions {
245
- nsCondition := getCondition (ns .Status .Conditions , expCondition .Type )
246
- if nsCondition == nil {
247
- t .Errorf ("Missing namespace status condition %v" , expCondition .Type )
248
- continue
229
+
230
+ // validate status conditions
231
+ if testInput .expectStatus != nil {
232
+ obj , err := mockClient .Tracker ().Get (schema.GroupVersionResource {Version : "v1" , Resource : "namespaces" }, testInput .testNamespace .Namespace , testInput .testNamespace .Name )
233
+ if err != nil {
234
+ t .Fatalf ("Unexpected error in getting the namespace: %v" , err )
235
+ }
236
+ ns , ok := obj .(* v1.Namespace )
237
+ if ! ok {
238
+ t .Fatalf ("Expected a namespace but received %v" , obj )
239
+ }
240
+ if ns .Status .Phase != testInput .expectStatus .Phase {
241
+ t .Fatalf ("Expected namespace status phase %v but received %v" , testInput .expectStatus .Phase , ns .Status .Phase )
242
+ }
243
+ for _ , expCondition := range testInput .expectStatus .Conditions {
244
+ nsCondition := getCondition (ns .Status .Conditions , expCondition .Type )
245
+ if nsCondition == nil {
246
+ t .Fatalf ("Missing namespace status condition %v" , expCondition .Type )
247
+ }
249
248
}
250
249
}
251
- }
250
+ })
252
251
}
253
252
}
254
253
0 commit comments