11package routeutils
22
33import (
4+ "testing"
5+
46 awssdk "github.com/aws/aws-sdk-go-v2/aws"
57 "github.com/go-logr/logr"
68 "github.com/stretchr/testify/assert"
79 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
810 gwv1 "sigs.k8s.io/gateway-api/apis/v1"
9- "testing"
1011)
1112
1213func Test_doesRouteAttachToGateway (t * testing.T ) {
@@ -231,11 +232,18 @@ func Test_doesRouteAttachToGateway(t *testing.T) {
231232}
232233
233234func Test_routeAllowsAttachmentToListener (t * testing.T ) {
235+ gw := gwv1.Gateway {
236+ ObjectMeta : metav1.ObjectMeta {
237+ Name : "gw" ,
238+ Namespace : "ns1" ,
239+ },
240+ }
234241 testCases := []struct {
235- name string
236- listener gwv1.Listener
237- route preLoadRouteDescriptor
238- result bool
242+ name string
243+ listener gwv1.Listener
244+ route preLoadRouteDescriptor
245+ result bool
246+ failedRouteCount int
239247 }{
240248 {
241249 name : "allows attachment section and port correct" ,
@@ -325,7 +333,8 @@ func Test_routeAllowsAttachmentToListener(t *testing.T) {
325333 Name : "sectionname" ,
326334 Port : 80 ,
327335 },
328- result : true ,
336+ result : true ,
337+ failedRouteCount : 3 ,
329338 },
330339 {
331340 name : "multiple parent refs one ref none attachment" ,
@@ -357,6 +366,45 @@ func Test_routeAllowsAttachmentToListener(t *testing.T) {
357366 Name : "sectionname" ,
358367 Port : 80 ,
359368 },
369+ failedRouteCount : 4 ,
370+ },
371+ {
372+ name : "section name mismatch" ,
373+ route : convertHTTPRoute (gwv1.HTTPRoute {
374+ Spec : gwv1.HTTPRouteSpec {
375+ CommonRouteSpec : gwv1.CommonRouteSpec {
376+ ParentRefs : []gwv1.ParentReference {
377+ {
378+ SectionName : (* gwv1 .SectionName )(awssdk .String ("wrongsection" )),
379+ },
380+ },
381+ },
382+ },
383+ }),
384+ listener : gwv1.Listener {
385+ Name : "sectionname" ,
386+ Port : 80 ,
387+ },
388+ failedRouteCount : 1 ,
389+ },
390+ {
391+ name : "port mismatch" ,
392+ route : convertHTTPRoute (gwv1.HTTPRoute {
393+ Spec : gwv1.HTTPRouteSpec {
394+ CommonRouteSpec : gwv1.CommonRouteSpec {
395+ ParentRefs : []gwv1.ParentReference {
396+ {
397+ Port : (* gwv1 .PortNumber )(awssdk .Int32 (443 )),
398+ },
399+ },
400+ },
401+ },
402+ }),
403+ listener : gwv1.Listener {
404+ Name : "sectionname" ,
405+ Port : 80 ,
406+ },
407+ failedRouteCount : 1 ,
360408 },
361409 }
362410
@@ -365,7 +413,9 @@ func Test_routeAllowsAttachmentToListener(t *testing.T) {
365413 helper := & routeAttachmentHelperImpl {
366414 logger : logr .Discard (),
367415 }
368- assert .Equal (t , tc .result , helper .routeAllowsAttachmentToListener (tc .listener , tc .route ))
416+ allowed , failedRouteData := helper .routeAllowsAttachmentToListener (gw , tc .listener , tc .route )
417+ assert .Equal (t , tc .result , allowed )
418+ assert .Equal (t , tc .failedRouteCount , len (failedRouteData ))
369419 })
370420 }
371421}
0 commit comments