@@ -270,16 +270,19 @@ func Test_listenerSetGatewayHandshake(t *testing.T) {
270270 }
271271}
272272
273- func Test_getListenerSets (t * testing.T ) {
273+ func Test_retrieveListenersFromListenerSets (t * testing.T ) {
274274 nsAll := gwv1 .NamespacesFromAll
275+ nsSame := gwv1 .NamespacesFromSame
275276
276277 testCases := []struct {
277- name string
278- listenerSets []* gwv1.ListenerSet
279- gw gwv1.Gateway
280- expectedCount int
281- expectedNames []gwv1.SectionName
282- expectErr bool
278+ name string
279+ listenerSets []* gwv1.ListenerSet
280+ gw gwv1.Gateway
281+ expectedListenerCount int
282+ expectedListenerNames []gwv1.SectionName
283+ expectedRejectedCount int
284+ expectedRejectedNames []string
285+ expectErr bool
283286 }{
284287 {
285288 name : "no listener sets in cluster" ,
@@ -293,7 +296,8 @@ func Test_getListenerSets(t *testing.T) {
293296 },
294297 },
295298 },
296- expectedCount : 0 ,
299+ expectedListenerCount : 0 ,
300+ expectedRejectedCount : 0 ,
297301 },
298302 {
299303 name : "one matching listener set with two listeners" ,
@@ -329,11 +333,12 @@ func Test_getListenerSets(t *testing.T) {
329333 },
330334 },
331335 },
332- expectedCount : 2 ,
333- expectedNames : []gwv1.SectionName {"listener-a" , "listener-b" },
336+ expectedListenerCount : 2 ,
337+ expectedListenerNames : []gwv1.SectionName {"listener-a" , "listener-b" },
338+ expectedRejectedCount : 0 ,
334339 },
335340 {
336- name : "listener set referencing different gateway is excluded " ,
341+ name : "irrelevant listener set referencing different gateway - not rejected, just ignored " ,
337342 listenerSets : []* gwv1.ListenerSet {
338343 {
339344 ObjectMeta : metav1.ObjectMeta {Name : "ls1" , Namespace : "ns1" },
@@ -361,35 +366,86 @@ func Test_getListenerSets(t *testing.T) {
361366 },
362367 },
363368 },
364- expectedCount : 0 ,
369+ expectedListenerCount : 0 ,
370+ expectedRejectedCount : 0 ,
371+ },
372+ {
373+ name : "rejected listener set - references gateway but namespace not allowed" ,
374+ listenerSets : []* gwv1.ListenerSet {
375+ {
376+ ObjectMeta : metav1.ObjectMeta {Name : "ls-rejected" , Namespace : "ns2" },
377+ Spec : gwv1.ListenerSetSpec {
378+ ParentRef : gwv1.ParentGatewayReference {
379+ Name : "my-gw" ,
380+ Namespace : (* gwv1 .Namespace )(awssdk .String ("ns1" )),
381+ },
382+ Listeners : []gwv1.ListenerEntry {
383+ {
384+ Name : "rejected-listener" ,
385+ Port : 80 ,
386+ Protocol : gwv1 .HTTPProtocolType ,
387+ },
388+ },
389+ },
390+ },
391+ },
392+ gw : gwv1.Gateway {
393+ ObjectMeta : metav1.ObjectMeta {Name : "my-gw" , Namespace : "ns1" },
394+ Spec : gwv1.GatewaySpec {
395+ AllowedListeners : & gwv1.AllowedListeners {
396+ Namespaces : & gwv1.ListenerNamespaces {
397+ From : & nsSame ,
398+ },
399+ },
400+ },
401+ },
402+ expectedListenerCount : 0 ,
403+ expectedRejectedCount : 1 ,
404+ expectedRejectedNames : []string {"ls-rejected" },
365405 },
366406 {
367- name : "mixed matching and non-matching listener sets" ,
407+ name : "mixed accepted, rejected, and irrelevant listener sets" ,
368408 listenerSets : []* gwv1.ListenerSet {
369409 {
370- ObjectMeta : metav1.ObjectMeta {Name : "ls-match " , Namespace : "ns1" },
410+ ObjectMeta : metav1.ObjectMeta {Name : "ls-accepted " , Namespace : "ns1" },
371411 Spec : gwv1.ListenerSetSpec {
372412 ParentRef : gwv1.ParentGatewayReference {
373413 Name : "my-gw" ,
374414 },
375415 Listeners : []gwv1.ListenerEntry {
376416 {
377- Name : "match-listener" ,
417+ Name : "accepted-listener" ,
418+ Port : 80 ,
419+ Protocol : gwv1 .HTTPProtocolType ,
420+ },
421+ },
422+ },
423+ },
424+ {
425+ ObjectMeta : metav1.ObjectMeta {Name : "ls-rejected" , Namespace : "ns2" },
426+ Spec : gwv1.ListenerSetSpec {
427+ ParentRef : gwv1.ParentGatewayReference {
428+ Name : "my-gw" ,
429+ Namespace : (* gwv1 .Namespace )(awssdk .String ("ns1" )),
430+ },
431+ Listeners : []gwv1.ListenerEntry {
432+ {
433+ Name : "rejected-listener" ,
378434 Port : 80 ,
379435 Protocol : gwv1 .HTTPProtocolType ,
380436 },
381437 },
382438 },
383439 },
384440 {
385- ObjectMeta : metav1.ObjectMeta {Name : "ls-nomatch " , Namespace : "ns1" },
441+ ObjectMeta : metav1.ObjectMeta {Name : "ls-irrelevant " , Namespace : "ns1" },
386442 Spec : gwv1.ListenerSetSpec {
387443 ParentRef : gwv1.ParentGatewayReference {
388444 Name : "other-gw" ,
389445 },
390446 Listeners : []gwv1.ListenerEntry {
391447 {
392- Name : "nomatch -listener" ,
448+ Name : "irrelevant -listener" ,
393449 Port : 80 ,
394450 Protocol : gwv1 .HTTPProtocolType ,
395451 },
@@ -402,13 +458,15 @@ func Test_getListenerSets(t *testing.T) {
402458 Spec : gwv1.GatewaySpec {
403459 AllowedListeners : & gwv1.AllowedListeners {
404460 Namespaces : & gwv1.ListenerNamespaces {
405- From : & nsAll ,
461+ From : & nsSame ,
406462 },
407463 },
408464 },
409465 },
410- expectedCount : 1 ,
411- expectedNames : []gwv1.SectionName {"match-listener" },
466+ expectedListenerCount : 1 ,
467+ expectedListenerNames : []gwv1.SectionName {"accepted-listener" },
468+ expectedRejectedCount : 1 ,
469+ expectedRejectedNames : []string {"ls-rejected" },
412470 },
413471 }
414472
@@ -426,20 +484,29 @@ func Test_getListenerSets(t *testing.T) {
426484 logger : logr .Discard (),
427485 }
428486
429- result , err := loader .getListenerSets (context .Background (), tc .gw )
487+ listeners , rejectedSets , err := loader .retrieveListenersFromListenerSets (context .Background (), tc .gw )
430488 if tc .expectErr {
431489 assert .Error (t , err )
432490 return
433491 }
434492 assert .NoError (t , err )
435- assert .Len (t , result , tc .expectedCount )
493+ assert .Len (t , listeners , tc .expectedListenerCount )
494+ assert .Len (t , rejectedSets , tc .expectedRejectedCount )
436495
437- if tc .expectedNames != nil {
496+ if tc .expectedListenerNames != nil {
438497 var names []gwv1.SectionName
439- for _ , l := range result {
498+ for _ , l := range listeners {
440499 names = append (names , l .Name )
441500 }
442- assert .Equal (t , tc .expectedNames , names )
501+ assert .Equal (t , tc .expectedListenerNames , names )
502+ }
503+
504+ if tc .expectedRejectedNames != nil {
505+ var rejectedNames []string
506+ for _ , rs := range rejectedSets {
507+ rejectedNames = append (rejectedNames , rs .Name )
508+ }
509+ assert .Equal (t , tc .expectedRejectedNames , rejectedNames )
443510 }
444511 })
445512 }
0 commit comments