Skip to content

Commit 6289c6e

Browse files
authored
Run tests in cmd/ in parallel (#2361)
1 parent aedc18d commit 6289c6e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ linters:
8888
- stylecheck
8989
- tenv
9090
- thelper
91+
- tparallel
9192
- typecheck
9293
- unconvert
9394
- unparam

cmd/gateway/commands_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ This test cannot be run with ginkgo. Ginkgo reports the following error:
5656
* See https://github.com/spf13/cobra/issues/2104.
5757
*/
5858
func TestRootCmd(t *testing.T) {
59+
t.Parallel()
5960
testCase := flagTestCase{
6061
name: "no flags",
6162
args: nil,
@@ -66,6 +67,7 @@ func TestRootCmd(t *testing.T) {
6667
}
6768

6869
func TestCommonFlagsValidation(t *testing.T) {
70+
t.Parallel()
6971
tests := []flagTestCase{
7072
{
7173
name: "valid flags",
@@ -131,16 +133,20 @@ func TestCommonFlagsValidation(t *testing.T) {
131133
}
132134

133135
for _, test := range tests {
136+
test := test
134137
t.Run(test.name+"_static_mode", func(t *testing.T) {
138+
t.Parallel()
135139
testFlag(t, createStaticModeCommand(), test)
136140
})
137141
t.Run(test.name+"_provisioner_mode", func(t *testing.T) {
142+
t.Parallel()
138143
testFlag(t, createProvisionerModeCommand(), test)
139144
})
140145
}
141146
}
142147

143148
func TestStaticModeCmdFlagValidation(t *testing.T) {
149+
t.Parallel()
144150
tests := []flagTestCase{
145151
{
146152
name: "valid flags",
@@ -381,14 +387,17 @@ func TestStaticModeCmdFlagValidation(t *testing.T) {
381387
// common flags validation is tested separately
382388

383389
for _, test := range tests {
390+
test := test
384391
t.Run(test.name, func(t *testing.T) {
392+
t.Parallel()
385393
cmd := createStaticModeCommand()
386394
testFlag(t, cmd, test)
387395
})
388396
}
389397
}
390398

391399
func TestProvisionerModeCmdFlagValidation(t *testing.T) {
400+
t.Parallel()
392401
testCase := flagTestCase{
393402
name: "valid flags",
394403
args: []string{
@@ -419,6 +428,7 @@ This test cannot be run with ginkgo. Ginkgo reports the following error for the
419428
* See https://github.com/spf13/cobra/issues/2104.
420429
*/
421430
func TestSleepCmdFlagValidation(t *testing.T) {
431+
t.Parallel()
422432
tests := []flagTestCase{
423433
{
424434
name: "valid flags",
@@ -451,14 +461,17 @@ func TestSleepCmdFlagValidation(t *testing.T) {
451461
}
452462

453463
for _, test := range tests {
464+
test := test
454465
t.Run(test.name, func(t *testing.T) {
466+
t.Parallel()
455467
cmd := createSleepCommand()
456468
testFlag(t, cmd, test)
457469
})
458470
}
459471
}
460472

461473
func TestParseFlags(t *testing.T) {
474+
t.Parallel()
462475
g := NewWithT(t)
463476

464477
flagSet := pflag.NewFlagSet("flagSet", 0)

cmd/gateway/validation_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
func TestValidateGatewayControllerName(t *testing.T) {
11+
t.Parallel()
1112
tests := []struct {
1213
name string
1314
value string
@@ -51,7 +52,9 @@ func TestValidateGatewayControllerName(t *testing.T) {
5152
}
5253

5354
for _, test := range tests {
55+
test := test
5456
t.Run(test.name, func(t *testing.T) {
57+
t.Parallel()
5558
g := NewWithT(t)
5659

5760
err := validateGatewayControllerName(test.value)
@@ -66,6 +69,7 @@ func TestValidateGatewayControllerName(t *testing.T) {
6669
}
6770

6871
func TestValidateResourceName(t *testing.T) {
72+
t.Parallel()
6973
tests := []struct {
7074
name string
7175
value string
@@ -114,7 +118,9 @@ func TestValidateResourceName(t *testing.T) {
114118
}
115119

116120
for _, test := range tests {
121+
test := test
117122
t.Run(test.name, func(t *testing.T) {
123+
t.Parallel()
118124
g := NewWithT(t)
119125

120126
err := validateResourceName(test.value)
@@ -129,6 +135,7 @@ func TestValidateResourceName(t *testing.T) {
129135
}
130136

131137
func TestValidateNamespaceName(t *testing.T) {
138+
t.Parallel()
132139
tests := []struct {
133140
name string
134141
value string
@@ -177,7 +184,9 @@ func TestValidateNamespaceName(t *testing.T) {
177184
}
178185

179186
for _, test := range tests {
187+
test := test
180188
t.Run(test.name, func(t *testing.T) {
189+
t.Parallel()
181190
g := NewWithT(t)
182191

183192
err := validateNamespaceName(test.value)
@@ -192,6 +201,7 @@ func TestValidateNamespaceName(t *testing.T) {
192201
}
193202

194203
func TestParseNamespacedResourceName(t *testing.T) {
204+
t.Parallel()
195205
tests := []struct {
196206
name string
197207
value string
@@ -239,7 +249,9 @@ func TestParseNamespacedResourceName(t *testing.T) {
239249
}
240250

241251
for _, test := range tests {
252+
test := test
242253
t.Run(test.name, func(t *testing.T) {
254+
t.Parallel()
243255
g := NewWithT(t)
244256

245257
nsName, err := parseNamespacedResourceName(test.value)
@@ -256,6 +268,7 @@ func TestParseNamespacedResourceName(t *testing.T) {
256268
}
257269

258270
func TestValidateQualifiedName(t *testing.T) {
271+
t.Parallel()
259272
tests := []struct {
260273
name string
261274
value string
@@ -304,7 +317,9 @@ func TestValidateQualifiedName(t *testing.T) {
304317
}
305318

306319
for _, test := range tests {
320+
test := test
307321
t.Run(test.name, func(t *testing.T) {
322+
t.Parallel()
308323
g := NewWithT(t)
309324

310325
err := validateQualifiedName(test.value)
@@ -318,6 +333,7 @@ func TestValidateQualifiedName(t *testing.T) {
318333
}
319334

320335
func TestValidateURL(t *testing.T) {
336+
t.Parallel()
321337
tests := []struct {
322338
name string
323339
url string
@@ -366,7 +382,9 @@ func TestValidateURL(t *testing.T) {
366382
}
367383

368384
for _, tc := range tests {
385+
tc := tc
369386
t.Run(tc.name, func(t *testing.T) {
387+
t.Parallel()
370388
g := NewWithT(t)
371389

372390
err := validateURL(tc.url)
@@ -380,6 +398,7 @@ func TestValidateURL(t *testing.T) {
380398
}
381399

382400
func TestValidateIP(t *testing.T) {
401+
t.Parallel()
383402
tests := []struct {
384403
name string
385404
expSubMsg string
@@ -406,7 +425,9 @@ func TestValidateIP(t *testing.T) {
406425
}
407426

408427
for _, tc := range tests {
428+
tc := tc
409429
t.Run(tc.name, func(t *testing.T) {
430+
t.Parallel()
410431
g := NewWithT(t)
411432

412433
err := validateIP(tc.ip)
@@ -420,6 +441,7 @@ func TestValidateIP(t *testing.T) {
420441
}
421442

422443
func TestValidateEndpoint(t *testing.T) {
444+
t.Parallel()
423445
tests := []struct {
424446
name string
425447
endp string
@@ -473,7 +495,9 @@ func TestValidateEndpoint(t *testing.T) {
473495
}
474496

475497
for _, tc := range tests {
498+
tc := tc
476499
t.Run(tc.name, func(t *testing.T) {
500+
t.Parallel()
477501
g := NewWithT(t)
478502

479503
err := validateEndpoint(tc.endp)
@@ -487,6 +511,7 @@ func TestValidateEndpoint(t *testing.T) {
487511
}
488512

489513
func TestValidatePort(t *testing.T) {
514+
t.Parallel()
490515
tests := []struct {
491516
name string
492517
port int
@@ -510,7 +535,9 @@ func TestValidatePort(t *testing.T) {
510535
}
511536

512537
for _, tc := range tests {
538+
tc := tc
513539
t.Run(tc.name, func(t *testing.T) {
540+
t.Parallel()
514541
g := NewWithT(t)
515542

516543
err := validatePort(tc.port)
@@ -524,6 +551,7 @@ func TestValidatePort(t *testing.T) {
524551
}
525552

526553
func TestEnsureNoPortCollisions(t *testing.T) {
554+
t.Parallel()
527555
g := NewWithT(t)
528556

529557
g.Expect(ensureNoPortCollisions(9113, 8081)).To(Succeed())

0 commit comments

Comments
 (0)