Skip to content

Commit bae6718

Browse files
author
Kate Osborn
committed
Add test to the names of test functions
1 parent ab796da commit bae6718

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

internal/mode/static/state/graph/graph_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ func TestBuildGraph(t *testing.T) {
357357
},
358358
TypeMeta: metav1.TypeMeta{Kind: kinds.ClientSettingsPolicy},
359359
Spec: ngfAPI.ClientSettingsPolicySpec{
360-
TargetRef: createRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr-1", testNs),
360+
TargetRef: createTestRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr-1", testNs),
361361
},
362362
}
363363
processedRoutePolicy := &Policy{
@@ -386,7 +386,7 @@ func TestBuildGraph(t *testing.T) {
386386
},
387387
TypeMeta: metav1.TypeMeta{Kind: kinds.ClientSettingsPolicy},
388388
Spec: ngfAPI.ClientSettingsPolicySpec{
389-
TargetRef: createRef(kinds.Gateway, gatewayv1.GroupName, "gateway-1", testNs),
389+
TargetRef: createTestRef(kinds.Gateway, gatewayv1.GroupName, "gateway-1", testNs),
390390
},
391391
}
392392
processedGwPolicy := &Policy{
@@ -1029,49 +1029,49 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
10291029
{
10301030
name: "relevant; policy references the winning gateway",
10311031
graph: getGraph(),
1032-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "gw", "test")),
1032+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "gw", "test")),
10331033
nsname: types.NamespacedName{Namespace: "test", Name: "ref-gw"},
10341034
expRelevant: true,
10351035
},
10361036
{
10371037
name: "relevant; policy references an ignored gateway",
10381038
graph: getGraph(),
1039-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "ignored", "test")),
1039+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "ignored", "test")),
10401040
nsname: types.NamespacedName{Namespace: "test", Name: "ref-ignored"},
10411041
expRelevant: true,
10421042
},
10431043
{
10441044
name: "relevant; policy references an httproute in the graph",
10451045
graph: getGraph(),
1046-
policy: getPolicy(createRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr", "test")),
1046+
policy: getPolicy(createTestRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr", "test")),
10471047
nsname: types.NamespacedName{Namespace: "test", Name: "ref-hr"},
10481048
expRelevant: true,
10491049
},
10501050
{
10511051
name: "relevant; policy references a grpcroute in the graph",
10521052
graph: getGraph(),
1053-
policy: getPolicy(createRef(kinds.GRPCRoute, gatewayv1.GroupName, "gr", "test")),
1053+
policy: getPolicy(createTestRef(kinds.GRPCRoute, gatewayv1.GroupName, "gr", "test")),
10541054
nsname: types.NamespacedName{Namespace: "test", Name: "ref-gr"},
10551055
expRelevant: true,
10561056
},
10571057
{
10581058
name: "irrelevant; policy does not reference a relevant gw or route in the graph",
10591059
graph: getGraph(),
1060-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "diff", "test")),
1060+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "diff", "test")),
10611061
nsname: types.NamespacedName{Namespace: "test", Name: "not-relevant"},
10621062
expRelevant: false,
10631063
},
10641064
{
10651065
name: "irrelevant; policy references an unsupported kind in the Gateway group",
10661066
graph: getGraph(),
1067-
policy: getPolicy(createRef("GatewayClass", gatewayv1.GroupName, "diff", "test")),
1067+
policy: getPolicy(createTestRef("GatewayClass", gatewayv1.GroupName, "diff", "test")),
10681068
nsname: types.NamespacedName{Namespace: "test", Name: "unsupported-kind"},
10691069
expRelevant: false,
10701070
},
10711071
{
10721072
name: "irrelevant; policy references an unsupported group",
10731073
graph: getGraph(),
1074-
policy: getPolicy(createRef(kinds.Gateway, "SomeGroup", "diff", "test")),
1074+
policy: getPolicy(createTestRef(kinds.Gateway, "SomeGroup", "diff", "test")),
10751075
nsname: types.NamespacedName{Namespace: "test", Name: "unsupported-group"},
10761076
expRelevant: false,
10771077
},
@@ -1081,7 +1081,7 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
10811081
g.Gateway = nil
10821082
return g
10831083
}),
1084-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "diff", "test")),
1084+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "diff", "test")),
10851085
nsname: types.NamespacedName{Namespace: "test", Name: "nil-gw"},
10861086
expRelevant: false,
10871087
},
@@ -1091,7 +1091,7 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
10911091
g.Gateway.Source = nil
10921092
return g
10931093
}),
1094-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "diff", "test")),
1094+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "diff", "test")),
10951095
nsname: types.NamespacedName{Namespace: "test", Name: "nil-gw-source"},
10961096
expRelevant: false,
10971097
},

internal/mode/static/state/graph/policies_test.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var testNs = "test"
2626
func 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

655655
func 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

Comments
 (0)