@@ -331,3 +331,76 @@ func TestEnsureIngressServiceForDataPlane(t *testing.T) {
331
331
})
332
332
}
333
333
}
334
+
335
+ func TestComparePorts (t * testing.T ) {
336
+ testCases := []struct {
337
+ name string
338
+ a []corev1.ServicePort
339
+ b []corev1.ServicePort
340
+ dataPlane * operatorv1beta1.DataPlane
341
+ expected bool
342
+ }{
343
+ {
344
+ name : "should return true when NodePort differs but not specified in DataPlane spec" ,
345
+ a : []corev1.ServicePort {{Name : "port-80" , Port : 80 , NodePort : 30080 }},
346
+ b : []corev1.ServicePort {{Name : "port-80" , Port : 80 , NodePort : 30081 }},
347
+ dataPlane : builder .NewDataPlaneBuilder ().
348
+ WithIngressServicePorts ([]operatorv1beta1.DataPlaneServicePort {
349
+ {
350
+ Name : "http" ,
351
+ Port : 80 ,
352
+ TargetPort : intstr .FromInt (8000 ),
353
+ // NodePort not specified
354
+ },
355
+ }).Build (),
356
+ expected : true ,
357
+ },
358
+ {
359
+ name : "should return false when NodePort differs and is specified in DataPlane spec" ,
360
+ a : []corev1.ServicePort {{Name : "port-80" , Port : 80 , NodePort : 30080 }},
361
+ b : []corev1.ServicePort {{Name : "port-80" , Port : 80 , NodePort : 30081 }},
362
+ dataPlane : builder .NewDataPlaneBuilder ().
363
+ WithIngressServicePorts ([]operatorv1beta1.DataPlaneServicePort {
364
+ {
365
+ Name : "http" ,
366
+ Port : 80 ,
367
+ TargetPort : intstr .FromInt (8000 ),
368
+ NodePort : 30080 ,
369
+ },
370
+ }).Build (),
371
+ expected : false ,
372
+ },
373
+ {
374
+ name : "should return true when multiple ports match except NodePort which is not specified" ,
375
+ a : []corev1.ServicePort {
376
+ {Name : "port-80" , Port : 80 , NodePort : 30080 },
377
+ {Name : "port-443" , Port : 443 , NodePort : 30443 },
378
+ },
379
+ b : []corev1.ServicePort {
380
+ {Name : "port-80" , Port : 80 , NodePort : 30081 },
381
+ {Name : "port-443" , Port : 443 , NodePort : 30444 },
382
+ },
383
+ dataPlane : builder .NewDataPlaneBuilder ().
384
+ WithIngressServicePorts ([]operatorv1beta1.DataPlaneServicePort {
385
+ {
386
+ Name : "http" ,
387
+ Port : 80 ,
388
+ TargetPort : intstr .FromInt (8000 ),
389
+ },
390
+ {
391
+ Name : "https" ,
392
+ Port : 443 ,
393
+ TargetPort : intstr .FromInt (8443 ),
394
+ },
395
+ }).Build (),
396
+ expected : true ,
397
+ },
398
+ }
399
+
400
+ for _ , tc := range testCases {
401
+ t .Run (tc .name , func (t * testing.T ) {
402
+ actual := comparePorts (tc .a , tc .b , tc .dataPlane )
403
+ require .Equal (t , tc .expected , actual )
404
+ })
405
+ }
406
+ }
0 commit comments