Skip to content

Commit

Permalink
fix test description
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Aug 5, 2024
1 parent be047a9 commit 38538dc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
6 changes: 5 additions & 1 deletion internal/mode/static/state/graph/gateway_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,15 @@ func validateListenerHostname(listener v1.Listener) (conds []conditions.Conditio
return nil, true
}

// getAndValidateListenerSupportedKinds validates the route kind and returns the supported kinds for the listener.
// The supported kinds are determined based on the listener's allowedRoutes field.
// If the listener does not specify allowedRoutes, listener determines allowed routes based on its protocol.
func getAndValidateListenerSupportedKinds(listener v1.Listener) (
[]conditions.Condition,
[]v1.RouteGroupKind,
) {
var conds []conditions.Condition
supportedKinds := make([]v1.RouteGroupKind, 0)
var supportedKinds []v1.RouteGroupKind

validRouteKind := func(kind v1.RouteGroupKind) bool {
if kind.Kind != v1.Kind(kinds.HTTPRoute) && kind.Kind != v1.Kind(kinds.GRPCRoute) {
Expand All @@ -243,6 +246,7 @@ func getAndValidateListenerSupportedKinds(listener v1.Listener) (
}

if listener.AllowedRoutes != nil && listener.AllowedRoutes.Kinds != nil {
supportedKinds = make([]v1.RouteGroupKind, 0, len(listener.AllowedRoutes.Kinds))
for _, kind := range listener.AllowedRoutes.Kinds {
if !validRouteKind(kind) {
msg := fmt.Sprintf("Unsupported route kind \"%s/%s\"", *kind.Group, kind.Kind)
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/state/graph/gateway_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func TestGetAndValidateListenerSupportedKinds(t *testing.T) {
protocol: v1.TCPProtocolType,
expectErr: false,
name: "unsupported protocol is ignored",
expected: []v1.RouteGroupKind{},
expected: nil,
},
{
protocol: v1.HTTPProtocolType,
Expand Down
3 changes: 1 addition & 2 deletions internal/mode/static/state/graph/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,7 @@ func TestBuildGateway(t *testing.T) {
Conditions: staticConds.NewListenerUnsupportedProtocol(
`protocol: Unsupported value: "TCP": supported values: "HTTP", "HTTPS"`,
),
Routes: map[RouteKey]*L7Route{},
SupportedKinds: []v1.RouteGroupKind{},
Routes: map[RouteKey]*L7Route{},
},
},
Valid: true,
Expand Down
4 changes: 1 addition & 3 deletions internal/mode/static/state/graph/route_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,6 @@ func isRouteNamespaceAllowedByListener(
}

// isRouteKindAllowedByListener checks if the route is allowed to attach to the listener.
// If the listener specifies allowed kinds, the route kind must be in the list.
// If the listener does not specify allowedRoutes, allowed routes are determined using the listener protocol.
func isRouteTypeAllowedByListener(listener *Listener, routeType RouteType) bool {
for _, kind := range listener.SupportedKinds {
if kind.Kind == convertRouteType(routeType) {
Expand All @@ -553,7 +551,7 @@ func convertRouteType(routeType RouteType) v1.Kind {
case RouteTypeGRPC:
return kinds.GRPCRoute
default:
return ""
panic(fmt.Sprintf("unsupported route type: %s", routeType))

Check warning on line 554 in internal/mode/static/state/graph/route_common.go

View check run for this annotation

Codecov / codecov/patch

internal/mode/static/state/graph/route_common.go#L553-L554

Added lines #L553 - L554 were not covered by tests
}
}

Expand Down
8 changes: 4 additions & 4 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: "grpcRoute attaches to listener with allowedRoutes set to grpcRoute",
name: "grpcRoute is allowed when listener supports grpcRoute kind",
routeType: RouteTypeGRPC,
listener: &Listener{
SupportedKinds: []gatewayv1.RouteGroupKind{
Expand All @@ -1753,7 +1753,7 @@ func TestAllowedRouteType(t *testing.T) {
expResult: true,
},
{
name: "grpcRoute attaches to listener with allowedRoutes set to grpcRoute and httpRoute",
name: "grpcRoute is allowed when listener supports grpcRoute and httpRoute kind",
routeType: RouteTypeGRPC,
listener: &Listener{
SupportedKinds: []gatewayv1.RouteGroupKind{
Expand All @@ -1764,7 +1764,7 @@ func TestAllowedRouteType(t *testing.T) {
expResult: true,
},
{
name: "grpcRoute not allowed to attach to listener with allowedRoutes set to httpRoute",
name: "grpcRoute is allowed when listener supports httpRoute kind",
routeType: RouteTypeGRPC,
listener: &Listener{
SupportedKinds: []gatewayv1.RouteGroupKind{
Expand All @@ -1774,7 +1774,7 @@ func TestAllowedRouteType(t *testing.T) {
expResult: false,
},
{
name: "httpRoute not allowed to attach to listener with allowedRoutes set to grpcRoute",
name: "httpRoute not allowed when listener supports grpcRoute kind",
routeType: RouteTypeHTTP,
listener: &Listener{
SupportedKinds: []gatewayv1.RouteGroupKind{
Expand Down

0 comments on commit 38538dc

Please sign in to comment.