@@ -35,8 +35,8 @@ const (
35
35
)
36
36
37
37
const (
38
- PolicyName = "test-policy"
39
- TargetRefFormat = "targetRef-name-%d"
38
+ PolicyNameFormat = "test-policy-%d "
39
+ TargetRefFormat = "targetRef-name-%d"
40
40
)
41
41
42
42
func TestClientSettingsPoliciesTargetRefKind (t * testing.T ) {
@@ -156,17 +156,19 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
156
156
},
157
157
) {
158
158
t .Helper ()
159
+ g := NewWithT (t )
159
160
160
161
// Get Kubernetes client from test framework
161
162
// This should be set up by your test framework to connect to a real cluster
162
163
k8sClient := getKubernetesClient (t )
163
164
164
165
policySpec := tt .policySpec
165
166
policySpec .TargetRef .Name = gatewayv1alpha2 .ObjectName (fmt .Sprintf (TargetRefFormat , time .Now ().UnixNano ()))
167
+ policyName := fmt .Sprintf (PolicyNameFormat , time .Now ().UnixNano ())
166
168
167
169
clientSettingsPolicy := & ngfAPIv1alpha1.ClientSettingsPolicy {
168
170
ObjectMeta : controllerruntime.ObjectMeta {
169
- Name : PolicyName ,
171
+ Name : policyName ,
170
172
Namespace : "default" ,
171
173
},
172
174
Spec : policySpec ,
@@ -182,17 +184,17 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
182
184
// Check if we expected errors
183
185
if len (tt .wantErrors ) == 0 {
184
186
if err != nil {
185
- t . Errorf ( "expected no error but got: %v" , err )
187
+ g . Expect ( err ). ToNot ( HaveOccurred () )
186
188
}
187
189
return
188
190
}
189
191
190
192
// We expected errors - validation should have failed
191
193
if err == nil {
192
- t . Errorf ( "expected validation error but policy was accepted" )
194
+ g . Expect ( err ). To ( HaveOccurred () )
193
195
return
194
196
}
195
- g := NewWithT ( t )
197
+
196
198
// Check that we got the expected error messages
197
199
for _ , wantError := range tt .wantErrors {
198
200
g .Expect (err .Error ()).To (ContainSubstring (wantError ), "Expected error '%s' not found in: %s" , wantError , err .Error ())
0 commit comments