@@ -252,6 +252,15 @@ func TestBuildGRPCRoute(t *testing.T) {
252
252
[]v1alpha2.GRPCRouteRule {grValidFilterRule },
253
253
)
254
254
255
+ convertedFilters := []v1.HTTPRouteFilter {
256
+ {
257
+ Type : v1 .HTTPRouteFilterRequestHeaderModifier ,
258
+ RequestHeaderModifier : & v1.HTTPHeaderFilter {
259
+ Remove : []string {"header" },
260
+ },
261
+ },
262
+ }
263
+
255
264
createAllValidValidator := func () * validationfakes.FakeHTTPFieldsValidator {
256
265
v := & validationfakes.FakeHTTPFieldsValidator {}
257
266
v .ValidateMethodInMatchReturns (true , nil )
@@ -351,7 +360,7 @@ func TestBuildGRPCRoute(t *testing.T) {
351
360
ValidFilters : true ,
352
361
Matches : convertGRPCMatches (grValidFilter .Spec .Rules [0 ].Matches ),
353
362
RouteBackendRefs : []RouteBackendRef {},
354
- Filters : convertGRPCFilters ( grValidFilter . Spec . Rules [ 0 ]. Filters ) ,
363
+ Filters : convertedFilters ,
355
364
},
356
365
},
357
366
},
@@ -630,3 +639,74 @@ func TestBuildGRPCRoute(t *testing.T) {
630
639
})
631
640
}
632
641
}
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