Skip to content

Commit da6afda

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

File tree

2 files changed

+70
-66
lines changed

2 files changed

+70
-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
@@ -359,7 +359,7 @@ func TestBuildGraph(t *testing.T) {
359359
},
360360
TypeMeta: metav1.TypeMeta{Kind: kinds.ClientSettingsPolicy},
361361
Spec: ngfAPI.ClientSettingsPolicySpec{
362-
TargetRef: createRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr-1"),
362+
TargetRef: createTestRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr-1"),
363363
},
364364
}
365365
processedRoutePolicy := &Policy{
@@ -388,7 +388,7 @@ func TestBuildGraph(t *testing.T) {
388388
},
389389
TypeMeta: metav1.TypeMeta{Kind: kinds.ClientSettingsPolicy},
390390
Spec: ngfAPI.ClientSettingsPolicySpec{
391-
TargetRef: createRef(kinds.Gateway, gatewayv1.GroupName, "gateway-1"),
391+
TargetRef: createTestRef(kinds.Gateway, gatewayv1.GroupName, "gateway-1"),
392392
},
393393
}
394394
processedGwPolicy := &Policy{
@@ -1031,49 +1031,49 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
10311031
{
10321032
name: "relevant; policy references the winning gateway",
10331033
graph: getGraph(),
1034-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "gw")),
1034+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "gw")),
10351035
nsname: types.NamespacedName{Namespace: "test", Name: "ref-gw"},
10361036
expRelevant: true,
10371037
},
10381038
{
10391039
name: "relevant; policy references an ignored gateway",
10401040
graph: getGraph(),
1041-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "ignored")),
1041+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "ignored")),
10421042
nsname: types.NamespacedName{Namespace: "test", Name: "ref-ignored"},
10431043
expRelevant: true,
10441044
},
10451045
{
10461046
name: "relevant; policy references an httproute in the graph",
10471047
graph: getGraph(),
1048-
policy: getPolicy(createRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr")),
1048+
policy: getPolicy(createTestRef(kinds.HTTPRoute, gatewayv1.GroupName, "hr")),
10491049
nsname: types.NamespacedName{Namespace: "test", Name: "ref-hr"},
10501050
expRelevant: true,
10511051
},
10521052
{
10531053
name: "relevant; policy references a grpcroute in the graph",
10541054
graph: getGraph(),
1055-
policy: getPolicy(createRef(kinds.GRPCRoute, gatewayv1.GroupName, "gr")),
1055+
policy: getPolicy(createTestRef(kinds.GRPCRoute, gatewayv1.GroupName, "gr")),
10561056
nsname: types.NamespacedName{Namespace: "test", Name: "ref-gr"},
10571057
expRelevant: true,
10581058
},
10591059
{
10601060
name: "irrelevant; policy does not reference a relevant gw or route in the graph",
10611061
graph: getGraph(),
1062-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "diff")),
1062+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "diff")),
10631063
nsname: types.NamespacedName{Namespace: "test", Name: "not-relevant"},
10641064
expRelevant: false,
10651065
},
10661066
{
10671067
name: "irrelevant; policy references an unsupported kind in the Gateway group",
10681068
graph: getGraph(),
1069-
policy: getPolicy(createRef("GatewayClass", gatewayv1.GroupName, "diff")),
1069+
policy: getPolicy(createTestRef("GatewayClass", gatewayv1.GroupName, "diff")),
10701070
nsname: types.NamespacedName{Namespace: "test", Name: "unsupported-kind"},
10711071
expRelevant: false,
10721072
},
10731073
{
10741074
name: "irrelevant; policy references an unsupported group",
10751075
graph: getGraph(),
1076-
policy: getPolicy(createRef(kinds.Gateway, "SomeGroup", "diff")),
1076+
policy: getPolicy(createTestRef(kinds.Gateway, "SomeGroup", "diff")),
10771077
nsname: types.NamespacedName{Namespace: "test", Name: "unsupported-group"},
10781078
expRelevant: false,
10791079
},
@@ -1083,7 +1083,7 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
10831083
g.Gateway = nil
10841084
return g
10851085
}),
1086-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "diff")),
1086+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "diff")),
10871087
nsname: types.NamespacedName{Namespace: "test", Name: "nil-gw"},
10881088
expRelevant: false,
10891089
},
@@ -1093,7 +1093,7 @@ func TestIsNGFPolicyRelevant(t *testing.T) {
10931093
g.Gateway.Source = nil
10941094
return g
10951095
}),
1096-
policy: getPolicy(createRef(kinds.Gateway, gatewayv1.GroupName, "diff")),
1096+
policy: getPolicy(createTestRef(kinds.Gateway, gatewayv1.GroupName, "diff")),
10971097
nsname: types.NamespacedName{Namespace: "test", Name: "nil-gw-source"},
10981098
expRelevant: false,
10991099
},

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

Lines changed: 59 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")
461-
grpcRef := createRef(kinds.GRPCRoute, v1.GroupName, "grpc")
462-
gatewayRef := createRef(kinds.Gateway, v1.GroupName, "gw")
463-
ignoredGatewayRef := createRef(kinds.Gateway, v1.GroupName, "ignored")
460+
hrRef := createTestRef(kinds.HTTPRoute, v1.GroupName, "hr")
461+
grpcRef := createTestRef(kinds.GRPCRoute, v1.GroupName, "grpc")
462+
gatewayRef := createTestRef(kinds.Gateway, v1.GroupName, "gw")
463+
ignoredGatewayRef := createTestRef(kinds.Gateway, v1.GroupName, "ignored")
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")
468-
hrWrongGroup := createRef(kinds.HTTPRoute, "WrongGroup", "hr")
469-
gatewayWrongGroupRef := createRef(kinds.Gateway, "WrongGroup", "gw")
470-
nonNGFGatewayRef := createRef(kinds.Gateway, v1.GroupName, "not-ours")
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")
468+
hrWrongGroup := createTestRef(kinds.HTTPRoute, "WrongGroup", "hr")
469+
gatewayWrongGroupRef := createTestRef(kinds.Gateway, "WrongGroup", "gw")
470+
nonNGFGatewayRef := createTestRef(kinds.Gateway, v1.GroupName, "not-ours")
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")
656+
hrRef := createTestRef(kinds.HTTPRoute, v1.GroupName, "hr")
657657
hrTargetRef := PolicyTargetRef{
658658
Kind: hrRef.Kind,
659659
Group: hrRef.Group,
660660
Nsname: types.NamespacedName{Namespace: testNs, Name: string(hrRef.Name)},
661661
}
662662

663-
grpcRef := createRef(kinds.GRPCRoute, v1.GroupName, "grpc")
663+
grpcRef := createTestRef(kinds.GRPCRoute, v1.GroupName, "grpc")
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,22 @@ func createPolicyWithAncestors(numAncestors int) policies.Policy {
818818
return policy
819819
}
820820

821-
func createPolicyAndKey(
821+
func createTestPolicyAndKey(
822822
gvk schema.GroupVersionKind,
823823
ref v1alpha2.LocalPolicyTargetReference,
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.LocalPolicyTargetReference, name string) policies.Policy {
832+
func createTestPolicy(
833+
gvk schema.GroupVersionKind,
834+
ref v1alpha2.LocalPolicyTargetReference,
835+
name string,
836+
) policies.Policy {
833837
return &policiesfakes.FakePolicy{
834838
GetNameStub: func() string {
835839
return name
@@ -850,14 +854,14 @@ func createPolicy(gvk schema.GroupVersionKind, ref v1alpha2.LocalPolicyTargetRef
850854
}
851855
}
852856

853-
func createPolicyKey(gvk schema.GroupVersionKind, name string) PolicyKey {
857+
func createTestPolicyKey(gvk schema.GroupVersionKind, name string) PolicyKey {
854858
return PolicyKey{
855859
NsName: types.NamespacedName{Namespace: testNs, Name: name},
856860
GVK: gvk,
857861
}
858862
}
859863

860-
func createRef(kind v1.Kind, group v1.Group, name string) v1alpha2.LocalPolicyTargetReference {
864+
func createTestRef(kind v1.Kind, group v1.Group, name string) v1alpha2.LocalPolicyTargetReference {
861865
return v1alpha2.LocalPolicyTargetReference{
862866
Group: group,
863867
Kind: kind,

0 commit comments

Comments
 (0)