@@ -790,11 +790,12 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
790
790
pol2 , pol2Key := createTestPolicyAndKey (policyGVK , "pol2" , hrRefCoffee , hrRefCoffeeTea )
791
791
792
792
tests := []struct {
793
- validator validation.PolicyValidator
794
- policies map [PolicyKey ]policies.Policy
795
- routes map [RouteKey ]* L7Route
796
- expProcessedPolicies map [PolicyKey ]* Policy
797
- name string
793
+ validator validation.PolicyValidator
794
+ policies map [PolicyKey ]policies.Policy
795
+ routes map [RouteKey ]* L7Route
796
+ name string
797
+ expConditions []conditions.Condition
798
+ valid bool
798
799
}{
799
800
{
800
801
name : "no overlap" ,
@@ -812,20 +813,7 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
812
813
NamespacedName : types.NamespacedName {Namespace : testNs , Name : "hr2" },
813
814
}: createTestRouteWithPaths ("hr2" , "/tea" ),
814
815
},
815
- expProcessedPolicies : map [PolicyKey ]* Policy {
816
- pol1Key : {
817
- Source : pol1 ,
818
- TargetRefs : []PolicyTargetRef {
819
- {
820
- Nsname : types.NamespacedName {Namespace : testNs , Name : "hr-coffee" },
821
- Kind : kinds .HTTPRoute ,
822
- Group : v1 .GroupName ,
823
- },
824
- },
825
- Ancestors : []PolicyAncestor {},
826
- Valid : true ,
827
- },
828
- },
816
+ valid : true ,
829
817
},
830
818
{
831
819
name : "policy references route that overlaps a non-referenced route" ,
@@ -843,27 +831,14 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
843
831
NamespacedName : types.NamespacedName {Namespace : testNs , Name : "hr2" },
844
832
}: createTestRouteWithPaths ("hr2" , "/coffee" ),
845
833
},
846
- expProcessedPolicies : map [PolicyKey ]* Policy {
847
- pol1Key : {
848
- Source : pol1 ,
849
- TargetRefs : []PolicyTargetRef {
850
- {
851
- Nsname : types.NamespacedName {Namespace : testNs , Name : "hr-coffee" },
852
- Kind : kinds .HTTPRoute ,
853
- Group : v1 .GroupName ,
854
- },
855
- },
856
- Ancestors : []PolicyAncestor {},
857
- Conditions : []conditions.Condition {
858
- {
859
- Type : "Accepted" ,
860
- Status : "False" ,
861
- Reason : "TargetConflict" ,
862
- Message : "Policy cannot be applied to target \" test/hr-coffee\" since another Route " +
863
- "\" test/hr2\" shares a hostname:port/path combination with this target" ,
864
- },
865
- },
866
- Valid : false ,
834
+ valid : false ,
835
+ expConditions : []conditions.Condition {
836
+ {
837
+ Type : "Accepted" ,
838
+ Status : "False" ,
839
+ Reason : "TargetConflict" ,
840
+ Message : "Policy cannot be applied to target \" test/hr-coffee\" since another Route " +
841
+ "\" test/hr2\" shares a hostname:port/path combination with this target" ,
867
842
},
868
843
},
869
844
},
@@ -883,25 +858,7 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
883
858
NamespacedName : types.NamespacedName {Namespace : testNs , Name : "hr-coffee-tea" },
884
859
}: createTestRouteWithPaths ("hr-coffee-tea" , "/coffee" , "/tea" ),
885
860
},
886
- expProcessedPolicies : map [PolicyKey ]* Policy {
887
- pol2Key : {
888
- Source : pol2 ,
889
- TargetRefs : []PolicyTargetRef {
890
- {
891
- Nsname : types.NamespacedName {Namespace : testNs , Name : "hr-coffee" },
892
- Kind : kinds .HTTPRoute ,
893
- Group : v1 .GroupName ,
894
- },
895
- {
896
- Nsname : types.NamespacedName {Namespace : testNs , Name : "hr-coffee-tea" },
897
- Kind : kinds .HTTPRoute ,
898
- Group : v1 .GroupName ,
899
- },
900
- },
901
- Ancestors : []PolicyAncestor {},
902
- Valid : true ,
903
- },
904
- },
861
+ valid : true ,
905
862
},
906
863
{
907
864
name : "policy references 2 routes that overlap with non-referenced route" ,
@@ -923,39 +880,21 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
923
880
NamespacedName : types.NamespacedName {Namespace : testNs , Name : "hr-coffee-latte" },
924
881
}: createTestRouteWithPaths ("hr-coffee-latte" , "/coffee" , "/latte" ),
925
882
},
926
- expProcessedPolicies : map [PolicyKey ]* Policy {
927
- pol2Key : {
928
- Source : pol2 ,
929
- TargetRefs : []PolicyTargetRef {
930
- {
931
- Nsname : types.NamespacedName {Namespace : testNs , Name : "hr-coffee" },
932
- Kind : kinds .HTTPRoute ,
933
- Group : v1 .GroupName ,
934
- },
935
- {
936
- Nsname : types.NamespacedName {Namespace : testNs , Name : "hr-coffee-tea" },
937
- Kind : kinds .HTTPRoute ,
938
- Group : v1 .GroupName ,
939
- },
940
- },
941
- Ancestors : []PolicyAncestor {},
942
- Conditions : []conditions.Condition {
943
- {
944
- Type : "Accepted" ,
945
- Status : "False" ,
946
- Reason : "TargetConflict" ,
947
- Message : "Policy cannot be applied to target \" test/hr-coffee\" since another Route " +
948
- "\" test/hr-coffee-latte\" shares a hostname:port/path combination with this target" ,
949
- },
950
- {
951
- Type : "Accepted" ,
952
- Status : "False" ,
953
- Reason : "TargetConflict" ,
954
- Message : "Policy cannot be applied to target \" test/hr-coffee-tea\" since another Route " +
955
- "\" test/hr-coffee-latte\" shares a hostname:port/path combination with this target" ,
956
- },
957
- },
958
- Valid : false ,
883
+ valid : false ,
884
+ expConditions : []conditions.Condition {
885
+ {
886
+ Type : "Accepted" ,
887
+ Status : "False" ,
888
+ Reason : "TargetConflict" ,
889
+ Message : "Policy cannot be applied to target \" test/hr-coffee\" since another Route " +
890
+ "\" test/hr-coffee-latte\" shares a hostname:port/path combination with this target" ,
891
+ },
892
+ {
893
+ Type : "Accepted" ,
894
+ Status : "False" ,
895
+ Reason : "TargetConflict" ,
896
+ Message : "Policy cannot be applied to target \" test/hr-coffee-tea\" since another Route " +
897
+ "\" test/hr-coffee-latte\" shares a hostname:port/path combination with this target" ,
959
898
},
960
899
},
961
900
},
@@ -975,7 +914,12 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
975
914
g := NewWithT (t )
976
915
977
916
processed := processPolicies (test .policies , test .validator , gateways , test .routes , nil )
978
- g .Expect (processed ).To (BeEquivalentTo (test .expProcessedPolicies ))
917
+ g .Expect (processed ).To (HaveLen (1 ))
918
+
919
+ for _ , pol := range processed {
920
+ g .Expect (pol .Valid ).To (Equal (test .valid ))
921
+ g .Expect (pol .Conditions ).To (Equal (test .expConditions ))
922
+ }
979
923
})
980
924
}
981
925
}
0 commit comments