Skip to content

Commit 83139ce

Browse files
committed
Use rand.Prime to attempt to keep policy names unique for each parallel test run
1 parent c5860e2 commit 83139ce

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

tests/cel/clientsettingspolicy_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package cel
22

33
import (
44
"context"
5+
"crypto/rand"
56
"fmt"
67
"testing"
7-
"time"
88

99
. "github.com/onsi/gomega"
1010
"k8s.io/apimachinery/pkg/runtime"
@@ -164,9 +164,11 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
164164

165165
g.Expect(err).ToNot(HaveOccurred())
166166

167+
primeNum, err := rand.Prime(rand.Reader, 64)
168+
g.Expect(err).ToNot(HaveOccurred())
167169
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)
170172

171173
clientSettingsPolicy := &ngfAPIv1alpha1.ClientSettingsPolicy{
172174
ObjectMeta: controllerruntime.ObjectMeta{
@@ -183,13 +185,15 @@ func validateClientSettingsPolicy(t *testing.T, tt struct {
183185
_ = k8sClient.Delete(context.Background(), clientSettingsPolicy)
184186
}()
185187

186-
// Check if we expected errors
187188
if len(tt.wantErrors) == 0 {
188189
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+
}
189195
}
190196

191-
g.Expect(err).To(HaveOccurred())
192-
193197
// Check that we got the expected error messages
194198
for _, wantError := range tt.wantErrors {
195199
g.Expect(err.Error()).To(ContainSubstring(wantError), "Expected error '%s' not found in: %s", wantError, err.Error())

tests/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ require (
5959
github.com/spf13/pflag v1.0.7 // indirect
6060
github.com/stretchr/testify v1.10.0 // indirect
6161
github.com/x448/float16 v0.8.4 // indirect
62+
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea // indirect
6263
go.uber.org/automaxprocs v1.6.0 // indirect
6364
go.yaml.in/yaml/v2 v2.4.2 // indirect
6465
golang.org/x/mod v0.26.0 // indirect

tests/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
135135
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
136136
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
137137
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
138+
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea h1:CyhwejzVGvZ3Q2PSbQ4NRRYn+ZWv5eS1vlaEusT+bAI=
139+
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea/go.mod h1:eNr558nEUjP8acGw8FFjTeWvSgU1stO7FAO6eknhHe4=
138140
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
139141
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
140142
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=

0 commit comments

Comments
 (0)