@@ -884,6 +884,23 @@ func hasParentFalseCondition(p *egv1a1.SecurityPolicy) bool {
884884 return false
885885}
886886
887+ func SetRouteParentContext (route RouteContext , parentRef gwapiv1.ParentReference ) {
888+ ctx := & RouteParentContext {ParentReference : & parentRef }
889+ switch r := route .(type ) {
890+ case * HTTPRouteContext :
891+ ctx .HTTPRoute = r .HTTPRoute
892+ case * GRPCRouteContext :
893+ ctx .GRPCRoute = r .GRPCRoute
894+ case * TLSRouteContext :
895+ ctx .TLSRoute = r .TLSRoute
896+ case * TCPRouteContext :
897+ ctx .TCPRoute = r .TCPRoute
898+ case * UDPRouteContext :
899+ ctx .UDPRoute = r .UDPRoute
900+ }
901+ route .SetRouteParentContext (parentRef , ctx )
902+ }
903+
887904// --- TCP branch: validateSecurityPolicyForTCP(...) returns err -> SetTranslationErrorForPolicyAncestors(...) + return
888905func Test_SecurityPolicy_TCP_Invalid_setsStatus_and_returns (t * testing.T ) {
889906 tr := & Translator {GatewayControllerName : "gateway.envoyproxy.io/gatewayclass-controller" }
@@ -923,6 +940,7 @@ func Test_SecurityPolicy_TCP_Invalid_setsStatus_and_returns(t *testing.T) {
923940 },
924941 },
925942 }
943+ SetRouteParentContext (tcpRoute , tcpRoute .Spec .ParentRefs [0 ])
926944
927945 // Create the target reference
928946 target := gwapiv1.LocalPolicyTargetReferenceWithSectionName {
@@ -1000,6 +1018,7 @@ func Test_SecurityPolicy_HTTP_Invalid_setsStatus_and_returns(t *testing.T) {
10001018 },
10011019 },
10021020 }
1021+ SetRouteParentContext (httpRoute , httpRoute .Spec .ParentRefs [0 ])
10031022
10041023 // Create the target reference
10051024 target := gwapiv1.LocalPolicyTargetReferenceWithSectionName {
0 commit comments