Skip to content

Commit ad62fba

Browse files
committed
use fake policy
1 parent 4fc8e0f commit ad62fba

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

internal/controller/state/graph/policies_test.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,22 +2356,42 @@ func (s *testNGFLogSink) WithName(_ string) logr.LogSink {
23562356

23572357
// createPolicyWithExistingGatewayStatus creates a fake policy with a gateway in its status ancestors.
23582358
func createPolicyWithExistingGatewayStatus(gatewayNsName types.NamespacedName, controllerName string) policies.Policy {
2359-
fakePolicy := &policiesfakes.FakePolicy{
2359+
ancestors := []v1alpha2.PolicyAncestorStatus{
2360+
{
2361+
ControllerName: v1.GatewayController(controllerName),
2362+
AncestorRef: v1.ParentReference{
2363+
Group: helpers.GetPointer[v1.Group](v1.GroupName),
2364+
Kind: helpers.GetPointer[v1.Kind](kinds.Gateway),
2365+
Namespace: (*v1.Namespace)(&gatewayNsName.Namespace),
2366+
Name: v1.ObjectName(gatewayNsName.Name),
2367+
},
2368+
},
2369+
}
2370+
return createFakePolicyWithAncestors("test-policy", "test", ancestors)
2371+
}
2372+
2373+
// createFakePolicy creates a basic fake policy with common defaults.
2374+
func createFakePolicy(name, namespace string) *policiesfakes.FakePolicy {
2375+
return &policiesfakes.FakePolicy{
2376+
GetNameStub: func() string { return name },
2377+
GetNamespaceStub: func() string { return namespace },
23602378
GetPolicyStatusStub: func() v1alpha2.PolicyStatus {
2361-
return v1alpha2.PolicyStatus{
2362-
Ancestors: []v1alpha2.PolicyAncestorStatus{
2363-
{
2364-
ControllerName: v1.GatewayController(controllerName),
2365-
AncestorRef: v1.ParentReference{
2366-
Group: helpers.GetPointer[v1.Group](v1.GroupName),
2367-
Kind: helpers.GetPointer[v1.Kind](kinds.Gateway),
2368-
Namespace: (*v1.Namespace)(&gatewayNsName.Namespace),
2369-
Name: v1.ObjectName(gatewayNsName.Name),
2370-
},
2371-
},
2372-
},
2373-
}
2379+
return v1alpha2.PolicyStatus{}
2380+
},
2381+
GetTargetRefsStub: func() []v1alpha2.LocalPolicyTargetReference {
2382+
return []v1alpha2.LocalPolicyTargetReference{}
23742383
},
23752384
}
2376-
return fakePolicy
2385+
}
2386+
2387+
// createFakePolicyWithAncestors creates a fake policy with specific ancestors.
2388+
func createFakePolicyWithAncestors(
2389+
name, namespace string,
2390+
ancestors []v1alpha2.PolicyAncestorStatus,
2391+
) *policiesfakes.FakePolicy {
2392+
policy := createFakePolicy(name, namespace)
2393+
policy.GetPolicyStatusStub = func() v1alpha2.PolicyStatus {
2394+
return v1alpha2.PolicyStatus{Ancestors: ancestors}
2395+
}
2396+
return policy
23772397
}

0 commit comments

Comments
 (0)