@@ -31,6 +31,7 @@ import (
3131 "github.com/stretchr/testify/assert"
3232 "github.com/stretchr/testify/require"
3333 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34+ "k8s.io/utils/ptr"
3435)
3536
3637func TestGatewayAPIRouter_Reconcile (t * testing.T ) {
@@ -516,3 +517,106 @@ func TestGatewayAPIRouter_makeFilters(t *testing.T) {
516517 assert .Equal (t , "" , filtersDiff )
517518 }
518519}
520+
521+ func TestGatewayAPIRouter_GetRoutes (t * testing.T ) {
522+ canary := newTestGatewayAPICanary ()
523+ mocks := newFixture (canary )
524+ router := & GatewayAPIRouter {
525+ gatewayAPIClient : mocks .meshClient ,
526+ kubeClient : mocks .kubeClient ,
527+ logger : mocks .logger ,
528+ }
529+
530+ httpRoute := & v1.HTTPRoute {
531+ ObjectMeta : metav1.ObjectMeta {
532+ Name : "podinfo" ,
533+ Generation : 1 ,
534+ },
535+ Spec : v1.HTTPRouteSpec {
536+ Rules : []v1.HTTPRouteRule {
537+ {
538+ BackendRefs : []v1.HTTPBackendRef {
539+ {
540+ BackendRef : v1.BackendRef {
541+ BackendObjectReference : v1.BackendObjectReference {
542+ Name : "podinfo-canary" ,
543+ },
544+ Weight : ptr .To (int32 (10 )),
545+ },
546+ },
547+ {
548+ BackendRef : v1.BackendRef {
549+ BackendObjectReference : v1.BackendObjectReference {
550+ Name : "podinfo-primary" ,
551+ },
552+ Weight : ptr .To (int32 (90 )),
553+ },
554+ },
555+ },
556+ },
557+ },
558+ CommonRouteSpec : v1.CommonRouteSpec {
559+ ParentRefs : []v1.ParentReference {
560+ {
561+ Name : "podinfo" ,
562+ },
563+ },
564+ },
565+ },
566+ }
567+ httpRoute , err := router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Create (context .TODO (), httpRoute , metav1.CreateOptions {})
568+ require .NoError (t , err )
569+
570+ t .Run ("httproute generation" , func (t * testing.T ) {
571+ httpRoute .ObjectMeta .Generation = 5
572+ httpRoute .Status .Parents = []v1.RouteParentStatus {
573+ {
574+ ParentRef : v1.ParentReference {
575+ Name : "podinfo" ,
576+ SectionName : ptr .To (v1 .SectionName ("https" )),
577+ },
578+ Conditions : []metav1.Condition {
579+ {
580+ Type : string (v1 .RouteConditionAccepted ),
581+ Status : metav1 .ConditionTrue ,
582+ ObservedGeneration : 1 ,
583+ },
584+ },
585+ },
586+ {
587+ ParentRef : v1.ParentReference {
588+ Name : "podinfo" ,
589+ },
590+ Conditions : []metav1.Condition {
591+ {
592+ Type : string (v1 .RouteConditionAccepted ),
593+ Status : metav1 .ConditionFalse ,
594+ ObservedGeneration : 4 ,
595+ },
596+ },
597+ },
598+ }
599+ httpRoute , err := router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Update (context .TODO (), httpRoute , metav1.UpdateOptions {})
600+ require .NoError (t , err )
601+
602+ _ , _ , _ , err = router .GetRoutes (canary )
603+ require .Error (t , err )
604+
605+ httpRoute .Status .Parents [1 ].Conditions [0 ].ObservedGeneration = 5
606+ _ , err = router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Update (context .TODO (), httpRoute , metav1.UpdateOptions {})
607+ require .NoError (t , err )
608+
609+ _ , _ , _ , err = router .GetRoutes (canary )
610+ require .Error (t , err )
611+
612+ httpRoute .Status .Parents [1 ].Conditions [0 ].Status = metav1 .ConditionTrue
613+ _ , err = router .gatewayAPIClient .GatewayapiV1 ().HTTPRoutes ("default" ).Update (context .TODO (), httpRoute , metav1.UpdateOptions {})
614+ require .NoError (t , err )
615+
616+ primaryWeight , canaryWeight , mirrored , err := router .GetRoutes (canary )
617+ require .NoError (t , err )
618+ assert .Equal (t , 90 , primaryWeight )
619+ assert .Equal (t , 10 , canaryWeight )
620+ assert .False (t , mirrored )
621+ })
622+ }
0 commit comments