Skip to content

Commit 8509c3b

Browse files
committed
Fix flaky test
1 parent cb06d8a commit 8509c3b

File tree

1 file changed

+37
-93
lines changed

1 file changed

+37
-93
lines changed

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

+37-93
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,12 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
790790
pol2, pol2Key := createTestPolicyAndKey(policyGVK, "pol2", hrRefCoffee, hrRefCoffeeTea)
791791

792792
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
798799
}{
799800
{
800801
name: "no overlap",
@@ -812,20 +813,7 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
812813
NamespacedName: types.NamespacedName{Namespace: testNs, Name: "hr2"},
813814
}: createTestRouteWithPaths("hr2", "/tea"),
814815
},
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,
829817
},
830818
{
831819
name: "policy references route that overlaps a non-referenced route",
@@ -843,27 +831,14 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
843831
NamespacedName: types.NamespacedName{Namespace: testNs, Name: "hr2"},
844832
}: createTestRouteWithPaths("hr2", "/coffee"),
845833
},
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",
867842
},
868843
},
869844
},
@@ -883,25 +858,7 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
883858
NamespacedName: types.NamespacedName{Namespace: testNs, Name: "hr-coffee-tea"},
884859
}: createTestRouteWithPaths("hr-coffee-tea", "/coffee", "/tea"),
885860
},
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,
905862
},
906863
{
907864
name: "policy references 2 routes that overlap with non-referenced route",
@@ -923,39 +880,21 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
923880
NamespacedName: types.NamespacedName{Namespace: testNs, Name: "hr-coffee-latte"},
924881
}: createTestRouteWithPaths("hr-coffee-latte", "/coffee", "/latte"),
925882
},
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",
959898
},
960899
},
961900
},
@@ -975,7 +914,12 @@ func TestProcessPolicies_RouteOverlap(t *testing.T) {
975914
g := NewWithT(t)
976915

977916
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+
}
979923
})
980924
}
981925
}

0 commit comments

Comments
 (0)