@@ -555,6 +555,93 @@ func Test_newHTTPRoute_LabelAndAnnotationPropagation(t *testing.T) {
555555 require .Equal (t , "ann-value-2" , httpRoute .Annotations ["custom-annotation-2" ])
556556}
557557
558+ func Test_newHTTPRoute_Hostnames_NotSet (t * testing.T ) {
559+ c := requireNewFakeClientWithIndexes (t )
560+
561+ // Minimal backend to satisfy newHTTPRoute validation.
562+ backend := & aigv1a1.AIServiceBackend {
563+ ObjectMeta : metav1.ObjectMeta {Name : "test-backend" , Namespace : "test-ns" },
564+ Spec : aigv1a1.AIServiceBackendSpec {
565+ BackendRef : gwapiv1.BackendObjectReference {Name : "some-backend" , Namespace : ptr .To (gwapiv1 .Namespace ("test-ns" ))},
566+ },
567+ }
568+ require .NoError (t , c .Create (context .Background (), backend ))
569+
570+ aiGatewayRoute := & aigv1a1.AIGatewayRoute {
571+ ObjectMeta : metav1.ObjectMeta {
572+ Name : "test-route" ,
573+ Namespace : "test-ns" ,
574+ },
575+ Spec : aigv1a1.AIGatewayRouteSpec {
576+ Rules : []aigv1a1.AIGatewayRouteRule {
577+ {
578+ BackendRefs : []aigv1a1.AIGatewayRouteRuleBackendRef {
579+ {Name : "test-backend" , Weight : ptr.To [int32 ](100 )},
580+ },
581+ },
582+ },
583+ },
584+ }
585+
586+ controller := & AIGatewayRouteController {client : c }
587+ httpRoute := & gwapiv1.HTTPRoute {
588+ ObjectMeta : metav1.ObjectMeta {
589+ Name : "test-route" ,
590+ Namespace : "test-ns" ,
591+ },
592+ }
593+
594+ err := controller .newHTTPRoute (context .Background (), httpRoute , aiGatewayRoute )
595+ require .NoError (t , err )
596+
597+ // Without spec.hostnames, Hostnames should remain empty.
598+ require .Empty (t , httpRoute .Spec .Hostnames )
599+ }
600+
601+ func Test_newHTTPRoute_Hostnames_Set (t * testing.T ) {
602+ c := requireNewFakeClientWithIndexes (t )
603+
604+ // Minimal backend to satisfy newHTTPRoute validation.
605+ backend := & aigv1a1.AIServiceBackend {
606+ ObjectMeta : metav1.ObjectMeta {Name : "test-backend" , Namespace : "test-ns" },
607+ Spec : aigv1a1.AIServiceBackendSpec {
608+ BackendRef : gwapiv1.BackendObjectReference {Name : "some-backend" , Namespace : ptr .To (gwapiv1 .Namespace ("test-ns" ))},
609+ },
610+ }
611+ require .NoError (t , c .Create (context .Background (), backend ))
612+
613+ aiGatewayRoute := & aigv1a1.AIGatewayRoute {
614+ ObjectMeta : metav1.ObjectMeta {
615+ Name : "test-route" ,
616+ Namespace : "test-ns" ,
617+ },
618+ Spec : aigv1a1.AIGatewayRouteSpec {
619+ Hostnames : []gwapiv1.Hostname {"api.example.com" , "*.example.net" , "sub.example.com" },
620+ Rules : []aigv1a1.AIGatewayRouteRule {
621+ {
622+ BackendRefs : []aigv1a1.AIGatewayRouteRuleBackendRef {
623+ {Name : "test-backend" , Weight : ptr.To [int32 ](100 )},
624+ },
625+ },
626+ },
627+ },
628+ }
629+
630+ controller := & AIGatewayRouteController {client : c , logger : logr .Discard ()}
631+ httpRoute := & gwapiv1.HTTPRoute {
632+ ObjectMeta : metav1.ObjectMeta {
633+ Name : "test-route" ,
634+ Namespace : "test-ns" ,
635+ },
636+ }
637+
638+ err := controller .newHTTPRoute (context .Background (), httpRoute , aiGatewayRoute )
639+ require .NoError (t , err )
640+
641+ expected := []gwapiv1.Hostname {"api.example.com" , "*.example.net" , "sub.example.com" }
642+ require .Equal (t , expected , httpRoute .Spec .Hostnames )
643+ }
644+
558645func TestAIGatewayRouteController_syncGateways_NamespaceDetermination (t * testing.T ) {
559646 fakeClient := requireNewFakeClientWithIndexes (t )
560647 eventCh := internaltesting .NewControllerEventChan [* gwapiv1.Gateway ]()
0 commit comments