Skip to content

Commit

Permalink
add more grpc route tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rboyer committed Aug 21, 2023
1 parent 0f77486 commit c90836f
Show file tree
Hide file tree
Showing 4 changed files with 509 additions and 116 deletions.
36 changes: 25 additions & 11 deletions internal/mesh/internal/types/grpc_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func RegisterGRPCRoute(r resource.Registry) {
func ValidateGRPCRoute(res *pbresource.Resource) error {
var route pbmesh.GRPCRoute

// TODO(rb):sync common stuff from HTTPRoute

if err := res.Data.UnmarshalTo(&route); err != nil {
return resource.NewErrDataParse(&route, err)
}
Expand All @@ -66,8 +64,6 @@ func ValidateGRPCRoute(res *pbresource.Resource) error {
}
}

// TODO(rb): port a bunch of validation from ServiceRouterConfigEntry.Validate

for j, match := range rule.Matches {
wrapMatchErr := func(err error) error {
return wrapRuleErr(resource.ErrInvalidListElement{
Expand All @@ -77,13 +73,23 @@ func ValidateGRPCRoute(res *pbresource.Resource) error {
})
}

if match.Method != nil && match.Method.Type == pbmesh.GRPCMethodMatchType_GRPC_METHOD_MATCH_TYPE_UNSPECIFIED {
merr = multierror.Append(merr, wrapMatchErr(
resource.ErrInvalidField{
Name: "method",
Wrapped: resource.ErrMissing,
},
))
if match.Method != nil {
if match.Method.Type == pbmesh.GRPCMethodMatchType_GRPC_METHOD_MATCH_TYPE_UNSPECIFIED {
merr = multierror.Append(merr, wrapMatchErr(
resource.ErrInvalidField{
Name: "type",
Wrapped: resource.ErrMissing,
},
))
}
if match.Method.Service == "" && match.Method.Method == "" {
merr = multierror.Append(merr, wrapMatchErr(
resource.ErrInvalidField{
Name: "service",
Wrapped: errors.New("at least one of \"service\" or \"method\" must be set"),
},
))
}
}

for k, header := range match.Headers {
Expand All @@ -103,6 +109,14 @@ func ValidateGRPCRoute(res *pbresource.Resource) error {
},
))
}
if header.Name == "" {
merr = multierror.Append(merr, wrapMatchHeaderErr(
resource.ErrInvalidField{
Name: "name",
Wrapped: resource.ErrMissing,
}),
)
}
}
}

Expand Down
Loading

0 comments on commit c90836f

Please sign in to comment.