@@ -289,6 +289,7 @@ func Test_getParentStatusKey(t *testing.T) {
289289 portPtr := func (p gwv1.PortNumber ) * gwv1.PortNumber {
290290 return & p
291291 }
292+ routeNamespace := "route-namespace"
292293
293294 tests := []struct {
294295 name string
@@ -309,6 +310,19 @@ func Test_getParentStatusKey(t *testing.T) {
309310 },
310311 want : "networking.k8s.io/Gateway/test-namespace/test-gateway/test-section/80" ,
311312 },
313+ {
314+ name : "no namespace should use route namespace" ,
315+ status : gwv1.RouteParentStatus {
316+ ParentRef : gwv1.ParentReference {
317+ Group : (* gwv1 .Group )(ptr .To ("networking.k8s.io" )),
318+ Kind : (* gwv1 .Kind )(ptr .To ("Gateway" )),
319+ Name : "test-gateway" ,
320+ SectionName : (* gwv1 .SectionName )(ptr .To ("test-section" )),
321+ Port : portPtr (80 ),
322+ },
323+ },
324+ want : "networking.k8s.io/Gateway/route-namespace/test-gateway/test-section/80" ,
325+ },
312326 {
313327 name : "no section or port" ,
314328 status : gwv1.RouteParentStatus {
@@ -325,7 +339,7 @@ func Test_getParentStatusKey(t *testing.T) {
325339
326340 for _ , tt := range tests {
327341 t .Run (tt .name , func (t * testing.T ) {
328- got := getParentStatusKey (tt .status .ParentRef )
342+ got := getParentStatusKey (tt .status .ParentRef , routeNamespace )
329343 if got != tt .want {
330344 t .Errorf ("getParentStatusKey() = %v, want %v" , got , tt .want )
331345 }
@@ -339,7 +353,7 @@ func TestEnqueue(t *testing.T) {
339353 routeData routeutils.RouteData
340354 routeStatusInfo routeutils.RouteStatusInfo
341355 routeMetadataDescriptor routeutils.RouteMetadata
342- parentRefGateway routeutils. ParentRefGateway
356+ parentRefGateway gwv1. ParentReference
343357
344358 validateEnqueued func (t * testing.T , enqueued []routeutils.EnqueuedType ) // Use the type here
345359 }{
@@ -355,7 +369,7 @@ func TestEnqueue(t *testing.T) {
355369 RouteNamespace : "test-namespace" ,
356370 RouteKind : "test-kind" ,
357371 },
358- ParentRefGateway : routeutils. ParentRefGateway {},
372+ ParentRef : gwv1. ParentReference {},
359373 },
360374 validateEnqueued : func (t * testing.T , enqueued []routeutils.EnqueuedType ) {
361375 assert .Len (t , enqueued , 1 )
@@ -378,7 +392,7 @@ func TestEnqueue(t *testing.T) {
378392 RouteNamespace : "test-namespace" ,
379393 RouteKind : "test-kind" ,
380394 },
381- ParentRefGateway : routeutils. ParentRefGateway {},
395+ ParentRef : gwv1. ParentReference {},
382396 },
383397 validateEnqueued : func (t * testing.T , enqueued []routeutils.EnqueuedType ) {
384398 assert .Len (t , enqueued , 1 )
@@ -400,7 +414,7 @@ func TestEnqueue(t *testing.T) {
400414 RouteNamespace : "test-namespace" ,
401415 RouteKind : "test-kind" ,
402416 },
403- ParentRefGateway : routeutils. ParentRefGateway {},
417+ ParentRef : gwv1. ParentReference {},
404418 },
405419 validateEnqueued : func (t * testing.T , enqueued []routeutils.EnqueuedType ) {
406420 assert .Len (t , enqueued , 1 )
@@ -425,6 +439,7 @@ func TestEnqueue(t *testing.T) {
425439}
426440
427441func Test_updateRouteStatus (t * testing.T ) {
442+ testNamespace := gwv1 .Namespace ("test-namespace" )
428443 tests := []struct {
429444 name string
430445 route client.Object
@@ -449,9 +464,9 @@ func Test_updateRouteStatus(t *testing.T) {
449464 Reason : string (gwv1 .RouteConditionAccepted ),
450465 Message : "route accepted" ,
451466 },
452- ParentRefGateway : routeutils. ParentRefGateway {
467+ ParentRef : gwv1. ParentReference {
453468 Name : "test-gateway" ,
454- Namespace : "test-namespace" ,
469+ Namespace : & testNamespace ,
455470 },
456471 },
457472 validateResult : func (t * testing.T , route client.Object ) {
@@ -718,3 +733,72 @@ func findCondition(conditions []metav1.Condition, conditionType string) *metav1.
718733 }
719734 return nil
720735}
736+
737+ func Test_getParentRefKeyFromRouteData (t * testing.T ) {
738+ testNamespace := gwv1 .Namespace ("test-namespace" )
739+ testGroup := gwv1 .Group ("test-group" )
740+ testKind := gwv1 .Kind ("test-kind" )
741+ routeNamespace := "route-namespace"
742+ tests := []struct {
743+ name string
744+ gatewayRef gwv1.ParentReference
745+ want string
746+ }{
747+ {
748+ name : "all fields provided" ,
749+ gatewayRef : gwv1.ParentReference {
750+ Group : & testGroup ,
751+ Kind : & testKind ,
752+ Namespace : & testNamespace ,
753+ Name : "test-gateway" ,
754+ SectionName : ptr .To (gwv1 .SectionName ("test-section" )),
755+ Port : ptr .To (gwv1 .PortNumber (80 )),
756+ },
757+ want : "test-group/test-kind/test-namespace/test-gateway/test-section/80" ,
758+ },
759+ {
760+ name : "no namespace provided" ,
761+ gatewayRef : gwv1.ParentReference {
762+ Group : & testGroup ,
763+ Kind : & testKind ,
764+ Name : "test-gateway" ,
765+ SectionName : ptr .To (gwv1 .SectionName ("test-section" )),
766+ Port : ptr .To (gwv1 .PortNumber (80 )),
767+ },
768+ want : "test-group/test-kind/route-namespace/test-gateway/test-section/80" ,
769+ },
770+ {
771+ name : "no section or port" ,
772+ gatewayRef : gwv1.ParentReference {
773+ Namespace : & testNamespace ,
774+ Name : "test-gateway" ,
775+ },
776+ want : "//test-namespace/test-gateway//" ,
777+ },
778+ {
779+ name : "with port only" ,
780+ gatewayRef : gwv1.ParentReference {
781+ Namespace : & testNamespace ,
782+ Name : "test-gateway" ,
783+ Port : ptr .To (gwv1 .PortNumber (443 )),
784+ },
785+ want : "//test-namespace/test-gateway//443" ,
786+ },
787+ {
788+ name : "with section only" ,
789+ gatewayRef : gwv1.ParentReference {
790+ Namespace : & testNamespace ,
791+ Name : "test-gateway" ,
792+ SectionName : ptr .To (gwv1 .SectionName ("https" )),
793+ },
794+ want : "//test-namespace/test-gateway/https/" ,
795+ },
796+ }
797+
798+ for _ , tt := range tests {
799+ t .Run (tt .name , func (t * testing.T ) {
800+ got := getParentRefKeyFromRouteData (tt .gatewayRef , routeNamespace )
801+ assert .Equal (t , tt .want , got )
802+ })
803+ }
804+ }
0 commit comments