@@ -35,8 +35,8 @@ const (
3535)
3636
3737const (
38- PolicyName = "test-policy"
39- TargetRefFormat = "targetRef-name-%d"
38+ PolicyNameFormat = "test-policy-%d "
39+ TargetRefFormat = "targetRef-name-%d"
4040)
4141
4242func TestClientSettingsPoliciesTargetRefKind (t * testing.T ) {
@@ -156,17 +156,19 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
156156},
157157) {
158158 t .Helper ()
159+ g := NewWithT (t )
159160
160161 // Get Kubernetes client from test framework
161162 // This should be set up by your test framework to connect to a real cluster
162163 k8sClient := getKubernetesClient (t )
163164
164165 policySpec := tt .policySpec
165166 policySpec .TargetRef .Name = gatewayv1alpha2 .ObjectName (fmt .Sprintf (TargetRefFormat , time .Now ().UnixNano ()))
167+ policyName := fmt .Sprintf (PolicyNameFormat , time .Now ().UnixNano ())
166168
167169 clientSettingsPolicy := & ngfAPIv1alpha1.ClientSettingsPolicy {
168170 ObjectMeta : controllerruntime.ObjectMeta {
169- Name : PolicyName ,
171+ Name : policyName ,
170172 Namespace : "default" ,
171173 },
172174 Spec : policySpec ,
@@ -182,17 +184,17 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
182184 // Check if we expected errors
183185 if len (tt .wantErrors ) == 0 {
184186 if err != nil {
185- t . Errorf ( "expected no error but got: %v" , err )
187+ g . Expect ( err ). ToNot ( HaveOccurred () )
186188 }
187189 return
188190 }
189191
190192 // We expected errors - validation should have failed
191193 if err == nil {
192- t . Errorf ( "expected validation error but policy was accepted" )
194+ g . Expect ( err ). To ( HaveOccurred () )
193195 return
194196 }
195- g := NewWithT ( t )
197+
196198 // Check that we got the expected error messages
197199 for _ , wantError := range tt .wantErrors {
198200 g .Expect (err .Error ()).To (ContainSubstring (wantError ), "Expected error '%s' not found in: %s" , wantError , err .Error ())
0 commit comments