Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests in cmd/ in parallel #2361

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ linters:
- stylecheck
- tenv
- thelper
- tparallel
- typecheck
- unconvert
- unparam
Expand Down
13 changes: 13 additions & 0 deletions cmd/gateway/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ This test cannot be run with ginkgo. Ginkgo reports the following error:
* See https://github.com/spf13/cobra/issues/2104.
*/
func TestRootCmd(t *testing.T) {
t.Parallel()
testCase := flagTestCase{
name: "no flags",
args: nil,
Expand All @@ -66,6 +67,7 @@ func TestRootCmd(t *testing.T) {
}

func TestCommonFlagsValidation(t *testing.T) {
t.Parallel()
tests := []flagTestCase{
{
name: "valid flags",
Expand Down Expand Up @@ -131,16 +133,20 @@ func TestCommonFlagsValidation(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name+"_static_mode", func(t *testing.T) {
t.Parallel()
testFlag(t, createStaticModeCommand(), test)
})
t.Run(test.name+"_provisioner_mode", func(t *testing.T) {
t.Parallel()
testFlag(t, createProvisionerModeCommand(), test)
})
}
}

func TestStaticModeCmdFlagValidation(t *testing.T) {
t.Parallel()
tests := []flagTestCase{
{
name: "valid flags",
Expand Down Expand Up @@ -381,14 +387,17 @@ func TestStaticModeCmdFlagValidation(t *testing.T) {
// common flags validation is tested separately

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
cmd := createStaticModeCommand()
testFlag(t, cmd, test)
})
}
}

func TestProvisionerModeCmdFlagValidation(t *testing.T) {
t.Parallel()
testCase := flagTestCase{
name: "valid flags",
args: []string{
Expand Down Expand Up @@ -419,6 +428,7 @@ This test cannot be run with ginkgo. Ginkgo reports the following error for the
* See https://github.com/spf13/cobra/issues/2104.
*/
func TestSleepCmdFlagValidation(t *testing.T) {
t.Parallel()
tests := []flagTestCase{
{
name: "valid flags",
Expand Down Expand Up @@ -451,14 +461,17 @@ func TestSleepCmdFlagValidation(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
cmd := createSleepCommand()
testFlag(t, cmd, test)
})
}
}

func TestParseFlags(t *testing.T) {
t.Parallel()
g := NewWithT(t)

flagSet := pflag.NewFlagSet("flagSet", 0)
Expand Down
28 changes: 28 additions & 0 deletions cmd/gateway/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestValidateGatewayControllerName(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
Expand Down Expand Up @@ -51,7 +52,9 @@ func TestValidateGatewayControllerName(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestValidateResourceName(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
Expand Down Expand Up @@ -114,7 +118,9 @@ func TestValidateResourceName(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestValidateNamespaceName(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
Expand Down Expand Up @@ -177,7 +184,9 @@ func TestValidateNamespaceName(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestParseNamespacedResourceName(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
Expand Down Expand Up @@ -239,7 +249,9 @@ func TestParseNamespacedResourceName(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestValidateQualifiedName(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value string
Expand Down Expand Up @@ -304,7 +317,9 @@ func TestValidateQualifiedName(t *testing.T) {
}

for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestValidateURL(t *testing.T) {
t.Parallel()
tests := []struct {
name string
url string
Expand Down Expand Up @@ -366,7 +382,9 @@ func TestValidateURL(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestValidateIP(t *testing.T) {
t.Parallel()
tests := []struct {
name string
expSubMsg string
Expand All @@ -406,7 +425,9 @@ func TestValidateIP(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestValidateEndpoint(t *testing.T) {
t.Parallel()
tests := []struct {
name string
endp string
Expand Down Expand Up @@ -473,7 +495,9 @@ func TestValidateEndpoint(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestValidatePort(t *testing.T) {
t.Parallel()
tests := []struct {
name string
port int
Expand All @@ -510,7 +535,9 @@ func TestValidatePort(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

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

func TestEnsureNoPortCollisions(t *testing.T) {
t.Parallel()
g := NewWithT(t)

g.Expect(ensureNoPortCollisions(9113, 8081)).To(Succeed())
Expand Down
Loading