@@ -146,10 +146,11 @@ func TestGetEndpointSliceWorkMeta(t *testing.T) {
146
146
util .MultiClusterServiceNameLabel : "test-service" ,
147
147
util .EndpointSliceWorkManagedByLabel : util .MultiClusterServiceKind ,
148
148
},
149
+ Finalizers : []string {util .MCSEndpointSliceDispatchControllerFinalizer },
149
150
},
150
151
},
151
152
{
152
- name : "Existing work for EndpointSlice" ,
153
+ name : "Existing work for EndpointSlice without finalizers " ,
153
154
existingWork : createExistingWork ("endpointslice-test-eps-default" , "test-cluster" , "ExistingController" ),
154
155
endpointSlice : createEndpointSliceForTest ("test-eps" , "default" , "test-service" , false ),
155
156
expectedMeta : metav1.ObjectMeta {
@@ -163,6 +164,51 @@ func TestGetEndpointSliceWorkMeta(t *testing.T) {
163
164
Finalizers : []string {util .MCSEndpointSliceDispatchControllerFinalizer },
164
165
},
165
166
},
167
+ {
168
+ name : "Existing work with existing finalizers" ,
169
+ existingWork : createExistingWorkWithFinalizers ("endpointslice-test-eps-default" , "test-cluster" , "ExistingController" , []string {"existing.finalizer" , "another.finalizer" }),
170
+ endpointSlice : createEndpointSliceForTest ("test-eps" , "default" , "test-service" , false ),
171
+ expectedMeta : metav1.ObjectMeta {
172
+ Name : "endpointslice-test-eps-default" ,
173
+ Namespace : "test-cluster" ,
174
+ Labels : map [string ]string {
175
+ util .MultiClusterServiceNamespaceLabel : "default" ,
176
+ util .MultiClusterServiceNameLabel : "test-service" ,
177
+ util .EndpointSliceWorkManagedByLabel : "ExistingController.MultiClusterService" ,
178
+ },
179
+ Finalizers : []string {"another.finalizer" , "existing.finalizer" , util .MCSEndpointSliceDispatchControllerFinalizer },
180
+ },
181
+ },
182
+ {
183
+ name : "Existing work with duplicate finalizer" ,
184
+ existingWork : createExistingWorkWithFinalizers ("endpointslice-test-eps-default" , "test-cluster" , "ExistingController" , []string {util .MCSEndpointSliceDispatchControllerFinalizer , "another.finalizer" }),
185
+ endpointSlice : createEndpointSliceForTest ("test-eps" , "default" , "test-service" , false ),
186
+ expectedMeta : metav1.ObjectMeta {
187
+ Name : "endpointslice-test-eps-default" ,
188
+ Namespace : "test-cluster" ,
189
+ Labels : map [string ]string {
190
+ util .MultiClusterServiceNamespaceLabel : "default" ,
191
+ util .MultiClusterServiceNameLabel : "test-service" ,
192
+ util .EndpointSliceWorkManagedByLabel : "ExistingController.MultiClusterService" ,
193
+ },
194
+ Finalizers : []string {"another.finalizer" , util .MCSEndpointSliceDispatchControllerFinalizer },
195
+ },
196
+ },
197
+ {
198
+ name : "Existing work without labels" ,
199
+ existingWork : createExistingWorkWithoutLabels ("endpointslice-test-eps-default" , "test-cluster" , []string {"existing.finalizer" }),
200
+ endpointSlice : createEndpointSliceForTest ("test-eps" , "default" , "test-service" , false ),
201
+ expectedMeta : metav1.ObjectMeta {
202
+ Name : "endpointslice-test-eps-default" ,
203
+ Namespace : "test-cluster" ,
204
+ Labels : map [string ]string {
205
+ util .MultiClusterServiceNamespaceLabel : "default" ,
206
+ util .MultiClusterServiceNameLabel : "test-service" ,
207
+ util .EndpointSliceWorkManagedByLabel : util .MultiClusterServiceKind ,
208
+ },
209
+ Finalizers : []string {"existing.finalizer" , util .MCSEndpointSliceDispatchControllerFinalizer },
210
+ },
211
+ },
166
212
{
167
213
name : "Nil EndpointSlice" ,
168
214
endpointSlice : nil ,
@@ -186,7 +232,10 @@ func TestGetEndpointSliceWorkMeta(t *testing.T) {
186
232
require .NoError (t , err )
187
233
assert .Equal (t , tc .expectedMeta .Name , meta .Name )
188
234
assert .Equal (t , tc .expectedMeta .Namespace , meta .Namespace )
189
- assert .Equal (t , tc .expectedMeta .Finalizers , meta .Finalizers )
235
+
236
+ assert .Equal (t , tc .expectedMeta .Finalizers , meta .Finalizers ,
237
+ "Finalizers do not match. Expected: %v, Got: %v" , tc .expectedMeta .Finalizers , meta .Finalizers )
238
+
190
239
assert .True (t , compareLabels (meta .Labels , tc .expectedMeta .Labels ),
191
240
"Labels do not match. Expected: %v, Got: %v" , tc .expectedMeta .Labels , meta .Labels )
192
241
}
@@ -325,6 +374,31 @@ func createExistingWork(name, namespace, managedBy string) *workv1alpha1.Work {
325
374
}
326
375
}
327
376
377
+ // Helper function to create an existing Work resource for testing with specific finalizers
378
+ func createExistingWorkWithFinalizers (name , namespace , managedBy string , finalizers []string ) * workv1alpha1.Work {
379
+ return & workv1alpha1.Work {
380
+ ObjectMeta : metav1.ObjectMeta {
381
+ Name : name ,
382
+ Namespace : namespace ,
383
+ Labels : map [string ]string {
384
+ util .EndpointSliceWorkManagedByLabel : managedBy ,
385
+ },
386
+ Finalizers : finalizers ,
387
+ },
388
+ }
389
+ }
390
+
391
+ // Helper function to create an existing Work resource for testing without labels
392
+ func createExistingWorkWithoutLabels (name , namespace string , finalizers []string ) * workv1alpha1.Work {
393
+ return & workv1alpha1.Work {
394
+ ObjectMeta : metav1.ObjectMeta {
395
+ Name : name ,
396
+ Namespace : namespace ,
397
+ Finalizers : finalizers ,
398
+ },
399
+ }
400
+ }
401
+
328
402
// Helper function to create a fake client with an optional existing Work
329
403
func createFakeClient (existingWork * workv1alpha1.Work ) client.Client {
330
404
scheme := setupSchemeEndpointCollect ()
0 commit comments