@@ -496,6 +496,7 @@ func TestBuildGRPCRoute(t *testing.T) {
496
496
expected * L7Route
497
497
name string
498
498
http2disabled bool
499
+ shouldPanic bool
499
500
}{
500
501
{
501
502
validator : createAllValidValidator (),
@@ -726,126 +727,22 @@ func TestBuildGRPCRoute(t *testing.T) {
726
727
name : "invalid route with disabled http2" ,
727
728
},
728
729
{
729
- validator : createAllValidValidator (),
730
- gr : grOneInvalid ,
731
- expected : & L7Route {
732
- Source : grOneInvalid ,
733
- RouteType : RouteTypeGRPC ,
734
- Valid : true ,
735
- Attachable : true ,
736
- ParentRefs : []ParentRef {
737
- {
738
- Idx : 0 ,
739
- Gateway : gatewayNsName ,
740
- SectionName : grOneInvalid .Spec .ParentRefs [0 ].SectionName ,
741
- },
742
- },
743
- Conditions : []conditions.Condition {
744
- staticConds .NewRoutePartiallyInvalid (
745
- `spec.rules[1].matches[0].headers[0].type: Unsupported value: "": supported values: "Exact", "RegularExpression"` ,
746
- ),
747
- },
748
- Spec : L7RouteSpec {
749
- Hostnames : grOneInvalid .Spec .Hostnames ,
750
- Rules : []RouteRule {
751
- {
752
- ValidMatches : true ,
753
- Filters : RouteRuleFilters {
754
- Valid : true ,
755
- Filters : []Filter {},
756
- },
757
- Matches : ConvertGRPCMatches (grOneInvalid .Spec .Rules [0 ].Matches ),
758
- RouteBackendRefs : []RouteBackendRef {},
759
- },
760
- {
761
- ValidMatches : false ,
762
- Filters : RouteRuleFilters {
763
- Valid : true ,
764
- Filters : []Filter {},
765
- },
766
- Matches : ConvertGRPCMatches (grOneInvalid .Spec .Rules [1 ].Matches ),
767
- RouteBackendRefs : []RouteBackendRef {},
768
- },
769
- },
770
- },
771
- },
772
- name : "invalid headers and valid method" ,
730
+ validator : createAllValidValidator (),
731
+ gr : grOneInvalid ,
732
+ shouldPanic : true ,
733
+ name : "invalid headers and valid method" ,
773
734
},
774
735
{
775
- validator : createAllValidValidator (),
776
- gr : grInvalidHeadersInvalidType ,
777
- expected : & L7Route {
778
- Source : grInvalidHeadersInvalidType ,
779
- RouteType : RouteTypeGRPC ,
780
- Valid : false ,
781
- Attachable : true ,
782
- ParentRefs : []ParentRef {
783
- {
784
- Idx : 0 ,
785
- Gateway : gatewayNsName ,
786
- SectionName : grInvalidHeadersInvalidType .Spec .ParentRefs [0 ].SectionName ,
787
- },
788
- },
789
- Conditions : []conditions.Condition {
790
- staticConds .NewRouteUnsupportedValue (
791
- `All rules are invalid: spec.rules[0].matches[0].headers[0].type: ` +
792
- `Unsupported value: "": supported values: "Exact", "RegularExpression"` ,
793
- ),
794
- },
795
- Spec : L7RouteSpec {
796
- Hostnames : grInvalidHeadersInvalidType .Spec .Hostnames ,
797
- Rules : []RouteRule {
798
- {
799
- ValidMatches : false ,
800
- Filters : RouteRuleFilters {
801
- Valid : true ,
802
- Filters : []Filter {},
803
- },
804
- Matches : ConvertGRPCMatches (grInvalidHeadersInvalidType .Spec .Rules [0 ].Matches ),
805
- RouteBackendRefs : []RouteBackendRef {},
806
- },
807
- },
808
- },
809
- },
810
- name : "invalid headers with invalid type" ,
736
+ validator : createAllValidValidator (),
737
+ gr : grInvalidHeadersInvalidType ,
738
+ shouldPanic : true ,
739
+ name : "invalid headers with invalid type" ,
811
740
},
812
741
{
813
- validator : createAllValidValidator (),
814
- gr : grInvalidHeadersEmptyType ,
815
- expected : & L7Route {
816
- Source : grInvalidHeadersEmptyType ,
817
- RouteType : RouteTypeGRPC ,
818
- Valid : false ,
819
- Attachable : true ,
820
- ParentRefs : []ParentRef {
821
- {
822
- Idx : 0 ,
823
- Gateway : gatewayNsName ,
824
- SectionName : grInvalidHeadersEmptyType .Spec .ParentRefs [0 ].SectionName ,
825
- },
826
- },
827
- Conditions : []conditions.Condition {
828
- staticConds .NewRouteUnsupportedValue (
829
- `All rules are invalid: spec.rules[0].matches[0].headers[0].type: ` +
830
- `Required value: cannot be empty` ,
831
- ),
832
- },
833
- Spec : L7RouteSpec {
834
- Hostnames : grInvalidHeadersEmptyType .Spec .Hostnames ,
835
- Rules : []RouteRule {
836
- {
837
- ValidMatches : false ,
838
- Filters : RouteRuleFilters {
839
- Valid : true ,
840
- Filters : []Filter {},
841
- },
842
- Matches : ConvertGRPCMatches (grInvalidHeadersEmptyType .Spec .Rules [0 ].Matches ),
843
- RouteBackendRefs : []RouteBackendRef {},
844
- },
845
- },
846
- },
847
- },
848
- name : "invalid headers with no header type specified" ,
742
+ validator : createAllValidValidator (),
743
+ gr : grInvalidHeadersEmptyType ,
744
+ shouldPanic : true ,
745
+ name : "invalid headers with no header type specified" ,
849
746
},
850
747
{
851
748
validator : createAllValidValidator (),
@@ -988,7 +885,6 @@ func TestBuildGRPCRoute(t *testing.T) {
988
885
},
989
886
},
990
887
},
991
-
992
888
name : "invalid snippet filter extension ref" ,
993
889
},
994
890
{
@@ -1028,7 +924,6 @@ func TestBuildGRPCRoute(t *testing.T) {
1028
924
},
1029
925
},
1030
926
},
1031
-
1032
927
name : "unresolvable snippet filter extension ref" ,
1033
928
},
1034
929
{
@@ -1072,7 +967,6 @@ func TestBuildGRPCRoute(t *testing.T) {
1072
967
},
1073
968
},
1074
969
},
1075
-
1076
970
name : "one invalid and one unresolvable snippet filter extension ref" ,
1077
971
},
1078
972
}
@@ -1088,8 +982,20 @@ func TestBuildGRPCRoute(t *testing.T) {
1088
982
{Namespace : "test" , Name : "sf" }: {Valid : true },
1089
983
}
1090
984
1091
- route := buildGRPCRoute (test .validator , test .gr , gatewayNsNames , test .http2disabled , snippetsFilters )
1092
- g .Expect (helpers .Diff (test .expected , route )).To (BeEmpty ())
985
+ if test .shouldPanic {
986
+ g .Expect (func () {
987
+ buildGRPCRoute (
988
+ test .validator ,
989
+ test .gr ,
990
+ gatewayNsNames ,
991
+ test .http2disabled ,
992
+ snippetsFilters ,
993
+ )
994
+ }).To (Panic ())
995
+ } else {
996
+ route := buildGRPCRoute (test .validator , test .gr , gatewayNsNames , test .http2disabled , snippetsFilters )
997
+ g .Expect (helpers .Diff (test .expected , route )).To (BeEmpty ())
998
+ }
1093
999
})
1094
1000
}
1095
1001
}
@@ -1215,10 +1121,6 @@ func TestConvertGRPCHeaderMatchType(t *testing.T) {
1215
1121
expected : helpers .GetPointer (v1 .HeaderMatchType ("unsupported" )),
1216
1122
shouldPanic : true ,
1217
1123
},
1218
- {
1219
- name : "nil match type" ,
1220
- expected : helpers .GetPointer (v1 .HeaderMatchExact ),
1221
- },
1222
1124
}
1223
1125
1224
1126
for _ , test := range tests {
0 commit comments