Skip to content

Commit 4486bd5

Browse files
committed
Ensure TestClientSettingsPoliciesTargetRefKind and TestClientSettingsPoliciesTargetRefGroup validate each test correctly
1 parent 8f74214 commit 4486bd5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/cel/clientsettingspolicy_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,13 @@ const (
3030
)
3131

3232
const (
33-
ExpectedTargetRefKindError = "TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute'"
34-
ExpectedTargetRefGroupError = "TargetRef Group must be gateway.networking.k8s.io."
33+
ExpectedTargetRefKindError = `TargetRef Kind must be one of: Gateway, HTTPRoute, or GRPCRoute`
34+
ExpectedTargetRefGroupError = `TargetRef Group must be gateway.networking.k8s.io.`
35+
)
36+
37+
const (
38+
PolicyName = "test-policy"
39+
TargetRefFormat = "targetRef-name-%d"
3540
)
3641

3742
func TestClientSettingsPoliciesTargetRefKind(t *testing.T) {
@@ -152,13 +157,15 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
152157
// This should be set up by your test framework to connect to a real cluster
153158
k8sClient := getKubernetesClient(t)
154159

160+
policySpec := tt.policySpec
161+
policySpec.TargetRef.Name = gatewayv1alpha2.ObjectName(fmt.Sprintf(TargetRefFormat, time.Now().UnixNano()))
162+
155163
clientSettingsPolicy := &ngfAPIv1alpha1.ClientSettingsPolicy{
156164
ObjectMeta: controllerruntime.ObjectMeta{
157-
// Create a unique name and namespace for the policy to avoid conflicts
158-
Name: fmt.Sprintf("test-policy-%d", time.Now().UnixNano()),
165+
Name: PolicyName,
159166
Namespace: "default",
160167
},
161-
Spec: tt.policySpec,
168+
Spec: policySpec,
162169
}
163170

164171
err := k8sClient.Create(context.Background(), clientSettingsPolicy)

0 commit comments

Comments
 (0)