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 75e6ab5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 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
38 changes: 31 additions & 7 deletions internal/mode/static/state/graph/route_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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,
},
}

Expand Down

0 comments on commit 75e6ab5

Please sign in to comment.