@@ -26,7 +26,7 @@ var testNs = "test"
26
26
func TestAttachPolicies (t * testing.T ) {
27
27
policyGVK := schema.GroupVersionKind {Group : "Group" , Version : "Version" , Kind : "Policy" }
28
28
29
- gwPolicyKey := createPolicyKey (policyGVK , "gw-policy" )
29
+ gwPolicyKey := createTestPolicyKey (policyGVK , "gw-policy" )
30
30
gwPolicy := & Policy {
31
31
Valid : true ,
32
32
Source : & policiesfakes.FakePolicy {},
@@ -37,7 +37,7 @@ func TestAttachPolicies(t *testing.T) {
37
37
},
38
38
}
39
39
40
- routePolicyKey := createPolicyKey (policyGVK , "route-policy" )
40
+ routePolicyKey := createTestPolicyKey (policyGVK , "route-policy" )
41
41
routePolicy := & Policy {
42
42
Valid : true ,
43
43
Source : & policiesfakes.FakePolicy {},
@@ -48,7 +48,7 @@ func TestAttachPolicies(t *testing.T) {
48
48
},
49
49
}
50
50
51
- grpcRoutePolicyKey := createPolicyKey (policyGVK , "grpc-route-policy" )
51
+ grpcRoutePolicyKey := createTestPolicyKey (policyGVK , "grpc-route-policy" )
52
52
grpcRoutePolicy := & Policy {
53
53
Valid : true ,
54
54
Source : & policiesfakes.FakePolicy {},
@@ -300,7 +300,7 @@ func TestAttachPolicyToRoute(t *testing.T) {
300
300
{
301
301
name : "no attachment; max ancestors" ,
302
302
route : createHTTPRoute (true /*valid*/ , true /*attachable*/ , true /*parentRefs*/ ),
303
- policy : & Policy {Source : createPolicyWithAncestors (16 )},
303
+ policy : & Policy {Source : createTestPolicyWithAncestors (16 )},
304
304
expAncestor : nil ,
305
305
expAttached : false ,
306
306
},
@@ -419,7 +419,7 @@ func TestAttachPolicyToGateway(t *testing.T) {
419
419
{
420
420
name : "not attached; max ancestors" ,
421
421
policy : & Policy {
422
- Source : createPolicyWithAncestors (16 ),
422
+ Source : createTestPolicyWithAncestors (16 ),
423
423
TargetRef : PolicyTargetRef {
424
424
Nsname : gatewayNsName ,
425
425
Kind : "Gateway" ,
@@ -457,28 +457,28 @@ func TestProcessPolicies(t *testing.T) {
457
457
458
458
// These refs reference objects that belong to NGF.
459
459
// 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 )
464
464
465
465
// These refs reference objects that do not belong to NGF.
466
466
// 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" )
482
482
483
483
allValidValidator := & policiesfakes.FakeValidator {}
484
484
@@ -653,14 +653,14 @@ func TestProcessPolicies(t *testing.T) {
653
653
}
654
654
655
655
func TestMarkConflictedPolicies (t * testing.T ) {
656
- hrRef := createRef (kinds .HTTPRoute , v1 .GroupName , "hr" , "test" )
656
+ hrRef := createTestRef (kinds .HTTPRoute , v1 .GroupName , "hr" , "test" )
657
657
hrTargetRef := PolicyTargetRef {
658
658
Kind : hrRef .Kind ,
659
659
Group : hrRef .Group ,
660
660
Nsname : types.NamespacedName {Namespace : string (* hrRef .Namespace ), Name : string (hrRef .Name )},
661
661
}
662
662
663
- grpcRef := createRef (kinds .GRPCRoute , v1 .GroupName , "grpc" , "test" )
663
+ grpcRef := createTestRef (kinds .GRPCRoute , v1 .GroupName , "grpc" , "test" )
664
664
grpcTargetRef := PolicyTargetRef {
665
665
Kind : grpcRef .Kind ,
666
666
Group : grpcRef .Group ,
@@ -680,13 +680,13 @@ func TestMarkConflictedPolicies(t *testing.T) {
680
680
{
681
681
name : "different policy types can not conflict" ,
682
682
policies : map [PolicyKey ]* Policy {
683
- createPolicyKey (orangeGVK , "orange" ): {
684
- Source : createPolicy (orangeGVK , hrRef , "orange" ),
683
+ createTestPolicyKey (orangeGVK , "orange" ): {
684
+ Source : createTestPolicy (orangeGVK , hrRef , "orange" ),
685
685
TargetRef : hrTargetRef ,
686
686
Valid : true ,
687
687
},
688
- createPolicyKey (appleGVK , "apple" ): {
689
- Source : createPolicy (appleGVK , hrRef , "apple" ),
688
+ createTestPolicyKey (appleGVK , "apple" ): {
689
+ Source : createTestPolicy (appleGVK , hrRef , "apple" ),
690
690
TargetRef : hrTargetRef ,
691
691
Valid : true ,
692
692
},
@@ -697,13 +697,13 @@ func TestMarkConflictedPolicies(t *testing.T) {
697
697
{
698
698
name : "policies of the same type but with different target refs can not conflict" ,
699
699
policies : map [PolicyKey ]* Policy {
700
- createPolicyKey (orangeGVK , "orange1" ): {
701
- Source : createPolicy (orangeGVK , hrRef , "orange1" ),
700
+ createTestPolicyKey (orangeGVK , "orange1" ): {
701
+ Source : createTestPolicy (orangeGVK , hrRef , "orange1" ),
702
702
TargetRef : hrTargetRef ,
703
703
Valid : true ,
704
704
},
705
- createPolicyKey (orangeGVK , "orange2" ): {
706
- Source : createPolicy (orangeGVK , grpcRef , "orange2" ),
705
+ createTestPolicyKey (orangeGVK , "orange2" ): {
706
+ Source : createTestPolicy (orangeGVK , grpcRef , "orange2" ),
707
707
TargetRef : grpcTargetRef ,
708
708
Valid : true ,
709
709
},
@@ -714,13 +714,13 @@ func TestMarkConflictedPolicies(t *testing.T) {
714
714
{
715
715
name : "invalid policies can not conflict" ,
716
716
policies : map [PolicyKey ]* Policy {
717
- createPolicyKey (orangeGVK , "valid" ): {
718
- Source : createPolicy (orangeGVK , hrRef , "valid" ),
717
+ createTestPolicyKey (orangeGVK , "valid" ): {
718
+ Source : createTestPolicy (orangeGVK , hrRef , "valid" ),
719
719
TargetRef : hrTargetRef ,
720
720
Valid : true ,
721
721
},
722
- createPolicyKey (orangeGVK , "invalid" ): {
723
- Source : createPolicy (orangeGVK , hrRef , "invalid" ),
722
+ createTestPolicyKey (orangeGVK , "invalid" ): {
723
+ Source : createTestPolicy (orangeGVK , hrRef , "invalid" ),
724
724
TargetRef : hrTargetRef ,
725
725
Valid : false ,
726
726
},
@@ -732,28 +732,28 @@ func TestMarkConflictedPolicies(t *testing.T) {
732
732
name : "when a policy conflicts with a policy that has greater precedence it's marked as invalid and a" +
733
733
" condition is added" ,
734
734
policies : map [PolicyKey ]* Policy {
735
- createPolicyKey (orangeGVK , "orange1" ): {
736
- Source : createPolicy (orangeGVK , hrRef , "orange1" ),
735
+ createTestPolicyKey (orangeGVK , "orange1" ): {
736
+ Source : createTestPolicy (orangeGVK , hrRef , "orange1" ),
737
737
TargetRef : hrTargetRef ,
738
738
Valid : true ,
739
739
},
740
- createPolicyKey (orangeGVK , "orange2" ): {
741
- Source : createPolicy (orangeGVK , hrRef , "orange2" ),
740
+ createTestPolicyKey (orangeGVK , "orange2" ): {
741
+ Source : createTestPolicy (orangeGVK , hrRef , "orange2" ),
742
742
TargetRef : hrTargetRef ,
743
743
Valid : true ,
744
744
},
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" ),
747
747
TargetRef : hrTargetRef ,
748
748
Valid : true ,
749
749
},
750
- createPolicyKey (orangeGVK , "orange4" ): {
751
- Source : createPolicy (orangeGVK , hrRef , "orange4" ),
750
+ createTestPolicyKey (orangeGVK , "orange4" ): {
751
+ Source : createTestPolicy (orangeGVK , hrRef , "orange4" ),
752
752
TargetRef : hrTargetRef ,
753
753
Valid : true ,
754
754
},
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" ),
757
757
TargetRef : hrTargetRef ,
758
758
Valid : true ,
759
759
},
@@ -805,7 +805,7 @@ func TestMarkConflictedPolicies(t *testing.T) {
805
805
}
806
806
}
807
807
808
- func createPolicyWithAncestors (numAncestors int ) policies.Policy {
808
+ func createTestPolicyWithAncestors (numAncestors int ) policies.Policy {
809
809
policy := & policiesfakes.FakePolicy {}
810
810
811
811
ancestors := make ([]v1alpha2.PolicyAncestorStatus , numAncestors )
@@ -818,18 +818,18 @@ func createPolicyWithAncestors(numAncestors int) policies.Policy {
818
818
return policy
819
819
}
820
820
821
- func createPolicyAndKey (
821
+ func createTestPolicyAndKey (
822
822
gvk schema.GroupVersionKind ,
823
823
ref v1alpha2.PolicyTargetReference ,
824
824
name string ,
825
825
) (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 )
828
828
829
829
return pol , key
830
830
}
831
831
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 {
833
833
return & policiesfakes.FakePolicy {
834
834
GetNameStub : func () string {
835
835
return name
@@ -847,14 +847,14 @@ func createPolicy(gvk schema.GroupVersionKind, ref v1alpha2.PolicyTargetReferenc
847
847
}
848
848
}
849
849
850
- func createPolicyKey (gvk schema.GroupVersionKind , name string ) PolicyKey {
850
+ func createTestPolicyKey (gvk schema.GroupVersionKind , name string ) PolicyKey {
851
851
return PolicyKey {
852
852
NsName : types.NamespacedName {Namespace : testNs , Name : name },
853
853
GVK : gvk ,
854
854
}
855
855
}
856
856
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 {
858
858
return v1alpha2.PolicyTargetReference {
859
859
Group : group ,
860
860
Kind : kind ,
0 commit comments