@@ -2,9 +2,9 @@ package cel
2
2
3
3
import (
4
4
"context"
5
+ "crypto/rand"
5
6
"fmt"
6
7
"testing"
7
- "time"
8
8
9
9
. "github.com/onsi/gomega"
10
10
"k8s.io/apimachinery/pkg/runtime"
@@ -164,9 +164,11 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
164
164
165
165
g .Expect (err ).ToNot (HaveOccurred ())
166
166
167
+ primeNum , err := rand .Prime (rand .Reader , 64 )
168
+ g .Expect (err ).ToNot (HaveOccurred ())
167
169
policySpec := tt .policySpec
168
- policySpec .TargetRef .Name = gatewayv1alpha2 .ObjectName (fmt .Sprintf (TargetRefFormat , time . Now (). UnixNano () ))
169
- policyName := fmt .Sprintf (PolicyNameFormat , time . Now (). UnixNano () )
170
+ policySpec .TargetRef .Name = gatewayv1alpha2 .ObjectName (fmt .Sprintf (TargetRefFormat , primeNum ))
171
+ policyName := fmt .Sprintf (PolicyNameFormat , primeNum )
170
172
171
173
clientSettingsPolicy := & ngfAPIv1alpha1.ClientSettingsPolicy {
172
174
ObjectMeta : controllerruntime.ObjectMeta {
@@ -183,13 +185,15 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
183
185
_ = k8sClient .Delete (context .Background (), clientSettingsPolicy )
184
186
}()
185
187
186
- // Check if we expected errors
187
188
if len (tt .wantErrors ) == 0 {
188
189
g .Expect (err ).ToNot (HaveOccurred ())
190
+ } else {
191
+ g .Expect (err ).To (HaveOccurred ())
192
+ for _ , wantError := range tt .wantErrors {
193
+ g .Expect (err .Error ()).To (ContainSubstring (wantError ))
194
+ }
189
195
}
190
196
191
- g .Expect (err ).To (HaveOccurred ())
192
-
193
197
// Check that we got the expected error messages
194
198
for _ , wantError := range tt .wantErrors {
195
199
g .Expect (err .Error ()).To (ContainSubstring (wantError ), "Expected error '%s' not found in: %s" , wantError , err .Error ())
0 commit comments