@@ -26,7 +26,7 @@ var testNs = "test"
2626func TestAttachPolicies (t * testing.T ) {
2727 policyGVK := schema.GroupVersionKind {Group : "Group" , Version : "Version" , Kind : "Policy" }
2828
29- gwPolicyKey := createPolicyKey (policyGVK , "gw-policy" )
29+ gwPolicyKey := createTestPolicyKey (policyGVK , "gw-policy" )
3030 gwPolicy := & Policy {
3131 Valid : true ,
3232 Source : & policiesfakes.FakePolicy {},
@@ -37,7 +37,7 @@ func TestAttachPolicies(t *testing.T) {
3737 },
3838 }
3939
40- routePolicyKey := createPolicyKey (policyGVK , "route-policy" )
40+ routePolicyKey := createTestPolicyKey (policyGVK , "route-policy" )
4141 routePolicy := & Policy {
4242 Valid : true ,
4343 Source : & policiesfakes.FakePolicy {},
@@ -48,7 +48,7 @@ func TestAttachPolicies(t *testing.T) {
4848 },
4949 }
5050
51- grpcRoutePolicyKey := createPolicyKey (policyGVK , "grpc-route-policy" )
51+ grpcRoutePolicyKey := createTestPolicyKey (policyGVK , "grpc-route-policy" )
5252 grpcRoutePolicy := & Policy {
5353 Valid : true ,
5454 Source : & policiesfakes.FakePolicy {},
@@ -300,7 +300,7 @@ func TestAttachPolicyToRoute(t *testing.T) {
300300 {
301301 name : "no attachment; max ancestors" ,
302302 route : createHTTPRoute (true /*valid*/ , true /*attachable*/ , true /*parentRefs*/ ),
303- policy : & Policy {Source : createPolicyWithAncestors (16 )},
303+ policy : & Policy {Source : createTestPolicyWithAncestors (16 )},
304304 expAncestor : nil ,
305305 expAttached : false ,
306306 },
@@ -419,7 +419,7 @@ func TestAttachPolicyToGateway(t *testing.T) {
419419 {
420420 name : "not attached; max ancestors" ,
421421 policy : & Policy {
422- Source : createPolicyWithAncestors (16 ),
422+ Source : createTestPolicyWithAncestors (16 ),
423423 TargetRef : PolicyTargetRef {
424424 Nsname : gatewayNsName ,
425425 Kind : "Gateway" ,
@@ -457,28 +457,28 @@ func TestProcessPolicies(t *testing.T) {
457457
458458 // These refs reference objects that belong to NGF.
459459 // Policies that contain these refs should be processed.
460- hrRef := createRef (kinds .HTTPRoute , v1 .GroupName , "hr" , testNs )
461- grpcRef := createRef (kinds .GRPCRoute , v1 .GroupName , "grpc" , testNs )
462- gatewayRef := createRef (kinds .Gateway , v1 .GroupName , "gw" , testNs )
463- ignoredGatewayRef := createRef (kinds .Gateway , v1 .GroupName , "ignored" , testNs )
460+ hrRef := createTestRef (kinds .HTTPRoute , v1 .GroupName , "hr" , testNs )
461+ grpcRef := createTestRef (kinds .GRPCRoute , v1 .GroupName , "grpc" , testNs )
462+ gatewayRef := createTestRef (kinds .Gateway , v1 .GroupName , "gw" , testNs )
463+ ignoredGatewayRef := createTestRef (kinds .Gateway , v1 .GroupName , "ignored" , testNs )
464464
465465 // These refs reference objects that do not belong to NGF.
466466 // Policies that contain these refs should NOT be processed.
467- hrDoesNotExistRef := createRef (kinds .HTTPRoute , v1 .GroupName , "dne" , testNs )
468- hrWrongGroup := createRef (kinds .HTTPRoute , "WrongGroup" , "hr" , testNs )
469- gatewayWrongGroupRef := createRef (kinds .Gateway , "WrongGroup" , "gw" , testNs )
470- nonNGFGatewayRef := createRef (kinds .Gateway , v1 .GroupName , "not-ours" , testNs )
471-
472- pol1 , pol1Key := createPolicyAndKey (policyGVK , hrRef , "pol1" )
473- pol2 , pol2Key := createPolicyAndKey (policyGVK , grpcRef , "pol2" )
474- pol3 , pol3Key := createPolicyAndKey (policyGVK , gatewayRef , "pol3" )
475- pol4 , pol4Key := createPolicyAndKey (policyGVK , ignoredGatewayRef , "pol4" )
476- pol5 , pol5Key := createPolicyAndKey (policyGVK , hrDoesNotExistRef , "pol5" )
477- pol6 , pol6Key := createPolicyAndKey (policyGVK , hrWrongGroup , "pol6" )
478- pol7 , pol7Key := createPolicyAndKey (policyGVK , gatewayWrongGroupRef , "pol7" )
479- pol8 , pol8Key := createPolicyAndKey (policyGVK , nonNGFGatewayRef , "pol8" )
480-
481- pol1Conflict , pol1ConflictKey := createPolicyAndKey (policyGVK , hrRef , "pol1-conflict" )
467+ hrDoesNotExistRef := createTestRef (kinds .HTTPRoute , v1 .GroupName , "dne" , testNs )
468+ hrWrongGroup := createTestRef (kinds .HTTPRoute , "WrongGroup" , "hr" , testNs )
469+ gatewayWrongGroupRef := createTestRef (kinds .Gateway , "WrongGroup" , "gw" , testNs )
470+ nonNGFGatewayRef := createTestRef (kinds .Gateway , v1 .GroupName , "not-ours" , testNs )
471+
472+ pol1 , pol1Key := createTestPolicyAndKey (policyGVK , hrRef , "pol1" )
473+ pol2 , pol2Key := createTestPolicyAndKey (policyGVK , grpcRef , "pol2" )
474+ pol3 , pol3Key := createTestPolicyAndKey (policyGVK , gatewayRef , "pol3" )
475+ pol4 , pol4Key := createTestPolicyAndKey (policyGVK , ignoredGatewayRef , "pol4" )
476+ pol5 , pol5Key := createTestPolicyAndKey (policyGVK , hrDoesNotExistRef , "pol5" )
477+ pol6 , pol6Key := createTestPolicyAndKey (policyGVK , hrWrongGroup , "pol6" )
478+ pol7 , pol7Key := createTestPolicyAndKey (policyGVK , gatewayWrongGroupRef , "pol7" )
479+ pol8 , pol8Key := createTestPolicyAndKey (policyGVK , nonNGFGatewayRef , "pol8" )
480+
481+ pol1Conflict , pol1ConflictKey := createTestPolicyAndKey (policyGVK , hrRef , "pol1-conflict" )
482482
483483 allValidValidator := & policiesfakes.FakeValidator {}
484484
@@ -653,14 +653,14 @@ func TestProcessPolicies(t *testing.T) {
653653}
654654
655655func TestMarkConflictedPolicies (t * testing.T ) {
656- hrRef := createRef (kinds .HTTPRoute , v1 .GroupName , "hr" , "test" )
656+ hrRef := createTestRef (kinds .HTTPRoute , v1 .GroupName , "hr" , "test" )
657657 hrTargetRef := PolicyTargetRef {
658658 Kind : hrRef .Kind ,
659659 Group : hrRef .Group ,
660660 Nsname : types.NamespacedName {Namespace : string (* hrRef .Namespace ), Name : string (hrRef .Name )},
661661 }
662662
663- grpcRef := createRef (kinds .GRPCRoute , v1 .GroupName , "grpc" , "test" )
663+ grpcRef := createTestRef (kinds .GRPCRoute , v1 .GroupName , "grpc" , "test" )
664664 grpcTargetRef := PolicyTargetRef {
665665 Kind : grpcRef .Kind ,
666666 Group : grpcRef .Group ,
@@ -680,13 +680,13 @@ func TestMarkConflictedPolicies(t *testing.T) {
680680 {
681681 name : "different policy types can not conflict" ,
682682 policies : map [PolicyKey ]* Policy {
683- createPolicyKey (orangeGVK , "orange" ): {
684- Source : createPolicy (orangeGVK , hrRef , "orange" ),
683+ createTestPolicyKey (orangeGVK , "orange" ): {
684+ Source : createTestPolicy (orangeGVK , hrRef , "orange" ),
685685 TargetRef : hrTargetRef ,
686686 Valid : true ,
687687 },
688- createPolicyKey (appleGVK , "apple" ): {
689- Source : createPolicy (appleGVK , hrRef , "apple" ),
688+ createTestPolicyKey (appleGVK , "apple" ): {
689+ Source : createTestPolicy (appleGVK , hrRef , "apple" ),
690690 TargetRef : hrTargetRef ,
691691 Valid : true ,
692692 },
@@ -697,13 +697,13 @@ func TestMarkConflictedPolicies(t *testing.T) {
697697 {
698698 name : "policies of the same type but with different target refs can not conflict" ,
699699 policies : map [PolicyKey ]* Policy {
700- createPolicyKey (orangeGVK , "orange1" ): {
701- Source : createPolicy (orangeGVK , hrRef , "orange1" ),
700+ createTestPolicyKey (orangeGVK , "orange1" ): {
701+ Source : createTestPolicy (orangeGVK , hrRef , "orange1" ),
702702 TargetRef : hrTargetRef ,
703703 Valid : true ,
704704 },
705- createPolicyKey (orangeGVK , "orange2" ): {
706- Source : createPolicy (orangeGVK , grpcRef , "orange2" ),
705+ createTestPolicyKey (orangeGVK , "orange2" ): {
706+ Source : createTestPolicy (orangeGVK , grpcRef , "orange2" ),
707707 TargetRef : grpcTargetRef ,
708708 Valid : true ,
709709 },
@@ -714,13 +714,13 @@ func TestMarkConflictedPolicies(t *testing.T) {
714714 {
715715 name : "invalid policies can not conflict" ,
716716 policies : map [PolicyKey ]* Policy {
717- createPolicyKey (orangeGVK , "valid" ): {
718- Source : createPolicy (orangeGVK , hrRef , "valid" ),
717+ createTestPolicyKey (orangeGVK , "valid" ): {
718+ Source : createTestPolicy (orangeGVK , hrRef , "valid" ),
719719 TargetRef : hrTargetRef ,
720720 Valid : true ,
721721 },
722- createPolicyKey (orangeGVK , "invalid" ): {
723- Source : createPolicy (orangeGVK , hrRef , "invalid" ),
722+ createTestPolicyKey (orangeGVK , "invalid" ): {
723+ Source : createTestPolicy (orangeGVK , hrRef , "invalid" ),
724724 TargetRef : hrTargetRef ,
725725 Valid : false ,
726726 },
@@ -732,28 +732,28 @@ func TestMarkConflictedPolicies(t *testing.T) {
732732 name : "when a policy conflicts with a policy that has greater precedence it's marked as invalid and a" +
733733 " condition is added" ,
734734 policies : map [PolicyKey ]* Policy {
735- createPolicyKey (orangeGVK , "orange1" ): {
736- Source : createPolicy (orangeGVK , hrRef , "orange1" ),
735+ createTestPolicyKey (orangeGVK , "orange1" ): {
736+ Source : createTestPolicy (orangeGVK , hrRef , "orange1" ),
737737 TargetRef : hrTargetRef ,
738738 Valid : true ,
739739 },
740- createPolicyKey (orangeGVK , "orange2" ): {
741- Source : createPolicy (orangeGVK , hrRef , "orange2" ),
740+ createTestPolicyKey (orangeGVK , "orange2" ): {
741+ Source : createTestPolicy (orangeGVK , hrRef , "orange2" ),
742742 TargetRef : hrTargetRef ,
743743 Valid : true ,
744744 },
745- createPolicyKey (orangeGVK , "orange3-conflicts-with-1" ): {
746- Source : createPolicy (orangeGVK , hrRef , "orange3-conflicts-with-1" ),
745+ createTestPolicyKey (orangeGVK , "orange3-conflicts-with-1" ): {
746+ Source : createTestPolicy (orangeGVK , hrRef , "orange3-conflicts-with-1" ),
747747 TargetRef : hrTargetRef ,
748748 Valid : true ,
749749 },
750- createPolicyKey (orangeGVK , "orange4" ): {
751- Source : createPolicy (orangeGVK , hrRef , "orange4" ),
750+ createTestPolicyKey (orangeGVK , "orange4" ): {
751+ Source : createTestPolicy (orangeGVK , hrRef , "orange4" ),
752752 TargetRef : hrTargetRef ,
753753 Valid : true ,
754754 },
755- createPolicyKey (orangeGVK , "orange5-conflicts-with-4" ): {
756- Source : createPolicy (orangeGVK , hrRef , "orange5-conflicts-with-4" ),
755+ createTestPolicyKey (orangeGVK , "orange5-conflicts-with-4" ): {
756+ Source : createTestPolicy (orangeGVK , hrRef , "orange5-conflicts-with-4" ),
757757 TargetRef : hrTargetRef ,
758758 Valid : true ,
759759 },
@@ -805,7 +805,7 @@ func TestMarkConflictedPolicies(t *testing.T) {
805805 }
806806}
807807
808- func createPolicyWithAncestors (numAncestors int ) policies.Policy {
808+ func createTestPolicyWithAncestors (numAncestors int ) policies.Policy {
809809 policy := & policiesfakes.FakePolicy {}
810810
811811 ancestors := make ([]v1alpha2.PolicyAncestorStatus , numAncestors )
@@ -818,18 +818,18 @@ func createPolicyWithAncestors(numAncestors int) policies.Policy {
818818 return policy
819819}
820820
821- func createPolicyAndKey (
821+ func createTestPolicyAndKey (
822822 gvk schema.GroupVersionKind ,
823823 ref v1alpha2.PolicyTargetReference ,
824824 name string ,
825825) (policies.Policy , PolicyKey ) {
826- pol := createPolicy (gvk , ref , name )
827- key := createPolicyKey (gvk , name )
826+ pol := createTestPolicy (gvk , ref , name )
827+ key := createTestPolicyKey (gvk , name )
828828
829829 return pol , key
830830}
831831
832- func createPolicy (gvk schema.GroupVersionKind , ref v1alpha2.PolicyTargetReference , name string ) policies.Policy {
832+ func createTestPolicy (gvk schema.GroupVersionKind , ref v1alpha2.PolicyTargetReference , name string ) policies.Policy {
833833 return & policiesfakes.FakePolicy {
834834 GetNameStub : func () string {
835835 return name
@@ -847,14 +847,14 @@ func createPolicy(gvk schema.GroupVersionKind, ref v1alpha2.PolicyTargetReferenc
847847 }
848848}
849849
850- func createPolicyKey (gvk schema.GroupVersionKind , name string ) PolicyKey {
850+ func createTestPolicyKey (gvk schema.GroupVersionKind , name string ) PolicyKey {
851851 return PolicyKey {
852852 NsName : types.NamespacedName {Namespace : testNs , Name : name },
853853 GVK : gvk ,
854854 }
855855}
856856
857- func createRef (kind v1.Kind , group v1.Group , name , ns string ) v1alpha2.PolicyTargetReference {
857+ func createTestRef (kind v1.Kind , group v1.Group , name , ns string ) v1alpha2.PolicyTargetReference {
858858 return v1alpha2.PolicyTargetReference {
859859 Group : group ,
860860 Kind : kind ,
0 commit comments