Skip to content

Commit 8a9a1ad

Browse files
committed
Review feedback
1 parent 07cbf95 commit 8a9a1ad

File tree

2 files changed

+84
-6
lines changed

2 files changed

+84
-6
lines changed

internal/mode/static/state/graph/grpcroute.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ func processGRPCRouteRules(
8686
matchesErrs = append(matchesErrs, validateGRPCMatch(validator, match, matchPath)...)
8787
}
8888

89-
if len(rule.Filters) > 0 {
90-
for j, filter := range rule.Filters {
91-
filterPath := rulePath.Child("filters").Index(j)
92-
filtersErrs = append(filtersErrs, validateGRPCFilter(validator, filter, filterPath)...)
93-
}
89+
for j, filter := range rule.Filters {
90+
filterPath := rulePath.Child("filters").Index(j)
91+
filtersErrs = append(filtersErrs, validateGRPCFilter(validator, filter, filterPath)...)
9492
}
9593

9694
backendRefs := make([]RouteBackendRef, 0, len(rule.BackendRefs))

internal/mode/static/state/graph/grpcroute_test.go

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ func TestBuildGRPCRoute(t *testing.T) {
252252
[]v1alpha2.GRPCRouteRule{grValidFilterRule},
253253
)
254254

255+
convertedFilters := []v1.HTTPRouteFilter{
256+
{
257+
Type: v1.HTTPRouteFilterRequestHeaderModifier,
258+
RequestHeaderModifier: &v1.HTTPHeaderFilter{
259+
Remove: []string{"header"},
260+
},
261+
},
262+
}
263+
255264
createAllValidValidator := func() *validationfakes.FakeHTTPFieldsValidator {
256265
v := &validationfakes.FakeHTTPFieldsValidator{}
257266
v.ValidateMethodInMatchReturns(true, nil)
@@ -351,7 +360,7 @@ func TestBuildGRPCRoute(t *testing.T) {
351360
ValidFilters: true,
352361
Matches: convertGRPCMatches(grValidFilter.Spec.Rules[0].Matches),
353362
RouteBackendRefs: []RouteBackendRef{},
354-
Filters: convertGRPCFilters(grValidFilter.Spec.Rules[0].Filters),
363+
Filters: convertedFilters,
355364
},
356365
},
357366
},
@@ -630,3 +639,74 @@ func TestBuildGRPCRoute(t *testing.T) {
630639
})
631640
}
632641
}
642+
643+
func TestConvertGRPCMatches(t *testing.T) {
644+
methodMatch := createGRPCMethodMatch("myService", "myMethod", "Exact").Matches
645+
646+
headersMatch := createGRPCHeadersMatch("Exact", "MyHeader", "SomeValue").Matches
647+
648+
expectedHTTPMatches := []v1.HTTPRouteMatch{
649+
{
650+
Path: &v1.HTTPPathMatch{
651+
Type: helpers.GetPointer(v1.PathMatchExact),
652+
Value: helpers.GetPointer("/myService/myMethod"),
653+
},
654+
Headers: []v1.HTTPHeaderMatch{},
655+
},
656+
}
657+
658+
expectedHeadersMatches := []v1.HTTPRouteMatch{
659+
{
660+
Path: &v1.HTTPPathMatch{
661+
Type: helpers.GetPointer(v1.PathMatchPathPrefix),
662+
Value: helpers.GetPointer("/"),
663+
},
664+
Headers: []v1.HTTPHeaderMatch{
665+
{
666+
Value: "SomeValue",
667+
Name: v1.HTTPHeaderName("MyHeader"),
668+
},
669+
},
670+
},
671+
}
672+
673+
expectedEmptyMatches := []v1.HTTPRouteMatch{
674+
{
675+
Path: &v1.HTTPPathMatch{
676+
Type: helpers.GetPointer(v1.PathMatchPathPrefix),
677+
Value: helpers.GetPointer("/"),
678+
},
679+
},
680+
}
681+
682+
tests := []struct {
683+
name string
684+
methodMatches []v1alpha2.GRPCRouteMatch
685+
expected []v1.HTTPRouteMatch
686+
}{
687+
{
688+
name: "exact match",
689+
methodMatches: methodMatch,
690+
expected: expectedHTTPMatches,
691+
},
692+
{
693+
name: "headers matches",
694+
methodMatches: headersMatch,
695+
expected: expectedHeadersMatches,
696+
},
697+
{
698+
name: "empty matches",
699+
methodMatches: []v1alpha2.GRPCRouteMatch{},
700+
expected: expectedEmptyMatches,
701+
},
702+
}
703+
704+
for _, test := range tests {
705+
t.Run(test.name, func(t *testing.T) {
706+
g := NewWithT(t)
707+
708+
httpMatches := convertGRPCMatches(test.methodMatches)
709+
g.Expect(helpers.Diff(test.expected, httpMatches)).To(BeEmpty())
710+
})
711+
}
712+
}

0 commit comments

Comments
 (0)