Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Aug 1, 2024
1 parent 6f86442 commit f58aecc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion internal/mode/static/state/graph/route_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
30 changes: 27 additions & 3 deletions internal/mode/static/state/graph/route_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,30 @@ func TestAllowedRouteType(t *testing.T) {
},
expResult: true,
},
{
name: "listener protocol set to tcp, grpcRoute is not allowed",
routeType: RouteTypeGRPC,
listener: &Listener{
Source: gatewayv1.Listener{
Protocol: gatewayv1.TCPProtocolType,
},
},
expResult: false,
},
{
name: "grpcRoute with listener allowedRoutes set to grpcRoute is allowed",
routeType: RouteTypeGRPC,
listener: &Listener{
Source: gatewayv1.Listener{
AllowedRoutes: &gatewayv1.AllowedRoutes{
Kinds: []gatewayv1.RouteGroupKind{
{Kind: kinds.GRPCRoute},
},
},
},
},
expResult: true,
},
{
name: "grpcRoute with listener allowedRoutes set to httpRoute is not allowed",
routeType: RouteTypeGRPC,
Expand Down Expand Up @@ -1791,18 +1815,18 @@ func TestAllowedRouteType(t *testing.T) {
expResult: false,
},
{
name: "grpcRoute with listener allowedRoutes set to grpcRoute is allowed",
name: "grpcRoute with listener allowedRoutes set to testRoute is not allowed",
routeType: RouteTypeGRPC,
listener: &Listener{
Source: gatewayv1.Listener{
AllowedRoutes: &gatewayv1.AllowedRoutes{
Kinds: []gatewayv1.RouteGroupKind{
{Kind: kinds.GRPCRoute},
{Kind: gatewayv1.Kind("testRoute")},
},
},
},
},
expResult: true,
expResult: false,
},
}

Expand Down

0 comments on commit f58aecc

Please sign in to comment.