From 75e6ab56a300ae7acdebb03761c81798cfee9209 Mon Sep 17 00:00:00 2001 From: Saloni Date: Wed, 31 Jul 2024 21:09:40 -0600 Subject: [PATCH] update tests --- .../mode/static/state/graph/route_common.go | 4 +- .../static/state/graph/route_common_test.go | 38 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/internal/mode/static/state/graph/route_common.go b/internal/mode/static/state/graph/route_common.go index ce23c24b74..7e205a0e3e 100644 --- a/internal/mode/static/state/graph/route_common.go +++ b/internal/mode/static/state/graph/route_common.go @@ -550,9 +550,11 @@ func isRouteTypeAllowedByListener(listener *Listener, routeType RouteType) bool return false } - if listener.Source.Protocol == v1.HTTPProtocolType || listener.Source.Protocol == v1.HTTPSProtocolType { + switch listener.Source.Protocol { + case v1.HTTPProtocolType, v1.HTTPSProtocolType: return routeType == RouteTypeHTTP || routeType == RouteTypeGRPC } + return false } diff --git a/internal/mode/static/state/graph/route_common_test.go b/internal/mode/static/state/graph/route_common_test.go index 8259101af5..94538be2cf 100644 --- a/internal/mode/static/state/graph/route_common_test.go +++ b/internal/mode/static/state/graph/route_common_test.go @@ -1743,7 +1743,7 @@ func TestAllowedRouteType(t *testing.T) { expResult bool }{ { - name: "httpRoute with listener protocol http", + name: "httpRoute attaches to listener with protocol http", routeType: RouteTypeHTTP, listener: &Listener{ Source: gatewayv1.Listener{ @@ -1753,7 +1753,7 @@ func TestAllowedRouteType(t *testing.T) { expResult: true, }, { - name: "grpcRoute with listener protocol https", + name: "grpcRoute attaches to listener with protocol https", routeType: RouteTypeGRPC, listener: &Listener{ Source: gatewayv1.Listener{ @@ -1763,7 +1763,31 @@ func TestAllowedRouteType(t *testing.T) { expResult: true, }, { - name: "grpcRoute with listener allowedRoutes set to httpRoute is not allowed", + name: "grpcRoute is not allowed to attach to listener with tcp protocol", + routeType: RouteTypeGRPC, + listener: &Listener{ + Source: gatewayv1.Listener{ + Protocol: gatewayv1.TCPProtocolType, + }, + }, + expResult: false, + }, + { + name: "grpcRoute attaches to listener with allowedRoutes set to grpcRoute", + routeType: RouteTypeGRPC, + listener: &Listener{ + Source: gatewayv1.Listener{ + AllowedRoutes: &gatewayv1.AllowedRoutes{ + Kinds: []gatewayv1.RouteGroupKind{ + {Kind: kinds.GRPCRoute}, + }, + }, + }, + }, + expResult: true, + }, + { + name: "grpcRoute not allowed to attach to listener with allowedRoutes set to httpRoute", routeType: RouteTypeGRPC, listener: &Listener{ Source: gatewayv1.Listener{ @@ -1777,7 +1801,7 @@ func TestAllowedRouteType(t *testing.T) { expResult: false, }, { - name: "httpRoute with listener allowedRoutes set to grpcRoute is not allowed", + name: "httpRoute not allowed to attach to listener with allowedRoutes set to grpcRoute", routeType: RouteTypeHTTP, listener: &Listener{ Source: gatewayv1.Listener{ @@ -1791,18 +1815,18 @@ func TestAllowedRouteType(t *testing.T) { expResult: false, }, { - name: "grpcRoute with listener allowedRoutes set to grpcRoute is allowed", + name: "grpcRoute not allowed to attach to listener with allowedRoutes set to testRoute", routeType: RouteTypeGRPC, listener: &Listener{ Source: gatewayv1.Listener{ AllowedRoutes: &gatewayv1.AllowedRoutes{ Kinds: []gatewayv1.RouteGroupKind{ - {Kind: kinds.GRPCRoute}, + {Kind: gatewayv1.Kind("testRoute")}, }, }, }, }, - expResult: true, + expResult: false, }, }