From 770ec256a0ec3d11c93167c648132e18b8f5be2c Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Tue, 4 Jun 2024 14:43:59 -0700 Subject: [PATCH] Enable more linters --- .golangci.yml | 9 +++- Makefile | 2 +- apis/v1alpha1/register.go | 4 +- cmd/gateway/commands_test.go | 13 ++++++ cmd/gateway/main.go | 2 +- cmd/gateway/validation.go | 4 +- cmd/gateway/validation_test.go | 28 ++++++++++++ .../framework/conditions/conditions_test.go | 2 + .../controller/controller_suite_test.go | 1 + .../controller/filter/filter_test.go | 3 ++ .../controller/index/endpointslice_test.go | 2 + .../controller/predicate/annotation_test.go | 6 +++ .../controller/predicate/gatewayclass_test.go | 1 + .../controller/predicate/service_test.go | 8 ++++ .../framework/controller/register_test.go | 3 ++ .../framework/events/events_suite_test.go | 1 + internal/framework/events/events_test.go | 1 + .../framework/gatewayclass/validate_test.go | 3 ++ internal/framework/helpers/helpers_test.go | 6 +++ internal/framework/kinds/kinds.go | 4 +- internal/framework/runnables/cronjob.go | 2 +- internal/framework/runnables/cronjob_test.go | 2 + .../framework/runnables/runnables_test.go | 3 ++ internal/framework/status/conditions_test.go | 3 ++ .../framework/status/status_suite_test.go | 1 + .../framework/status/updater_retry_test.go | 3 ++ .../provisioner/provisioner_suite_test.go | 1 + internal/mode/static/config_updater_test.go | 8 ++++ internal/mode/static/handler.go | 8 ++-- internal/mode/static/health_test.go | 1 + .../mode/static/log_level_setters_test.go | 3 ++ internal/mode/static/manager.go | 4 +- internal/mode/static/manager_test.go | 6 +++ .../static/metrics/collectors/controller.go | 2 +- .../mode/static/metrics/collectors/nginx.go | 4 +- .../metrics/collectors/nginx_runtime.go | 4 +- .../nginx/config/base_http_config_test.go | 1 + .../mode/static/nginx/config/convert_test.go | 1 + .../static/nginx/config/generator_test.go | 1 + internal/mode/static/nginx/config/maps.go | 2 +- .../mode/static/nginx/config/maps_test.go | 2 + internal/mode/static/nginx/config/servers.go | 10 ++--- .../mode/static/nginx/config/servers_test.go | 45 ++++++++++++++++++- .../mode/static/nginx/config/split_clients.go | 2 +- .../static/nginx/config/split_clients_test.go | 21 +++++++++ .../static/nginx/config/telemetry_test.go | 2 + .../static/nginx/config/upstreams_test.go | 6 +++ .../nginx/config/validation/common_test.go | 3 ++ .../nginx/config/validation/framework_test.go | 3 ++ .../nginx/config/validation/generic_test.go | 5 +++ .../config/validation/http_filters_test.go | 7 +++ .../config/validation/http_njs_match_test.go | 7 +++ .../nginx/config/validation/http_validator.go | 2 +- .../nginx/config/variable_names_test.go | 6 +++ .../mode/static/nginx/config/version_test.go | 1 + .../mode/static/nginx/file/file_suite_test.go | 1 + .../mode/static/nginx/file/folders_test.go | 4 ++ .../mode/static/nginx/file/os_filemanager.go | 2 +- .../mode/static/nginx/runtime/manager_test.go | 3 ++ .../nginx/runtime/runtime_suite_test.go | 1 + .../mode/static/nginx/runtime/verify_test.go | 6 +++ .../policies/clientsettings/generator_test.go | 4 ++ .../policies/clientsettings/validator_test.go | 8 ++++ .../policies/observability/generator_test.go | 5 +++ .../policies/observability/validator_test.go | 8 ++++ .../static/policies/policies_suite_test.go | 1 + internal/mode/static/sort/sort_test.go | 6 +++ .../static/state/changed_predicate_test.go | 6 +++ .../static/state/dataplane/configuration.go | 2 +- .../state/dataplane/configuration_test.go | 26 +++++++++++ .../static/state/dataplane/convert_test.go | 13 ++++++ .../mode/static/state/dataplane/sort_test.go | 1 + .../static/state/graph/backend_refs_test.go | 23 ++++++++++ .../state/graph/backend_tls_policy_test.go | 6 +++ .../static/state/graph/configmaps_test.go | 6 +++ internal/mode/static/state/graph/gateway.go | 2 +- .../state/graph/gateway_listener_test.go | 20 +++++++++ .../mode/static/state/graph/gateway_test.go | 9 ++++ .../static/state/graph/gatewayclass_test.go | 6 +++ .../mode/static/state/graph/graph_test.go | 10 +++++ internal/mode/static/state/graph/grpcroute.go | 2 +- .../mode/static/state/graph/grpcroute_test.go | 10 +++++ .../mode/static/state/graph/httproute_test.go | 18 ++++++++ .../mode/static/state/graph/namespace_test.go | 6 +++ .../static/state/graph/nginxproxy_test.go | 12 +++++ .../mode/static/state/graph/policies_test.go | 15 +++++++ .../state/graph/policy_ancestor_test.go | 6 +++ .../state/graph/reference_grant_test.go | 7 +++ .../mode/static/state/graph/route_common.go | 12 ++--- .../static/state/graph/route_common_test.go | 25 +++++++++++ .../mode/static/state/graph/secret_test.go | 1 + .../mode/static/state/graph/service_test.go | 3 ++ .../static/state/graph/validation_test.go | 3 ++ .../static/state/resolver/resolver_test.go | 6 +++ .../resolver/service_resolver_suite_test.go | 1 + .../mode/static/state/state_suite_test.go | 1 + internal/mode/static/state/store.go | 4 +- internal/mode/static/state/store_test.go | 3 ++ internal/mode/static/static_suite_test.go | 1 + .../static/status/prepare_requests_test.go | 18 ++++++++ .../mode/static/status/status_setters_test.go | 33 ++++++++++++++ internal/mode/static/telemetry/data_test.go | 2 + .../mode/static/telemetry/exporter_test.go | 1 + .../mode/static/telemetry/job_worker_test.go | 2 + .../mode/static/telemetry/platform_test.go | 3 ++ .../static/telemetry/telemetry_suite_test.go | 1 + internal/mode/static/usage/job_worker_test.go | 5 +++ internal/mode/static/usage/reporter_test.go | 3 ++ internal/mode/static/usage/secret_test.go | 3 ++ tests/framework/load.go | 2 +- tests/framework/prometheus.go | 2 +- tests/framework/resourcemanager.go | 6 +-- tests/suite/system_suite_test.go | 1 + 113 files changed, 634 insertions(+), 48 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 041ff220a3..859cefb60b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,11 @@ linters-settings: - name: blank-imports - name: context-as-argument - name: context-keys-type + - name: dot-imports + arguments: + - allowedPackages: + - github.com/onsi/gomega + - github.com/onsi/ginkgo/v2 - name: empty-block - name: error-naming - name: error-return @@ -44,6 +49,7 @@ linters: - errorlint - ginkgolinter - gocyclo + - godot - gofmt - gofumpt - goimports @@ -56,15 +62,16 @@ linters: - misspell - nilerr - noctx + - paralleltest - predeclared - revive - staticcheck + - tparallel - typecheck - unconvert - unparam - unused - wastedassign - disable-all: true issues: max-issues-per-linter: 0 max-same-issues: 0 diff --git a/Makefile b/Makefile index 047dd875db..a90f06a8c0 100644 --- a/Makefile +++ b/Makefile @@ -178,7 +178,7 @@ check-golangci-lint: .PHONY: lint lint: check-golangci-lint ## Run golangci-lint against code - golangci-lint run + golangci-lint run --fix .PHONY: unit-test unit-test: ## Run unit tests for the go code diff --git a/apis/v1alpha1/register.go b/apis/v1alpha1/register.go index c0f23fcac3..bacf47d737 100644 --- a/apis/v1alpha1/register.go +++ b/apis/v1alpha1/register.go @@ -9,10 +9,10 @@ import ( // GroupName specifies the group name used to register the objects. const GroupName = "gateway.nginx.org" -// SchemeGroupVersion is group version used to register these objects +// SchemeGroupVersion is group version used to register these objects. var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} -// Resource takes an unqualified resource and returns a Group qualified GroupResource +// Resource takes an unqualified resource and returns a Group qualified GroupResource. func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } diff --git a/cmd/gateway/commands_test.go b/cmd/gateway/commands_test.go index c2ae80a238..308ee5209b 100644 --- a/cmd/gateway/commands_test.go +++ b/cmd/gateway/commands_test.go @@ -55,6 +55,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, @@ -65,6 +66,7 @@ func TestRootCmd(t *testing.T) { } func TestCommonFlagsValidation(t *testing.T) { + t.Parallel() tests := []flagTestCase{ { name: "valid flags", @@ -130,16 +132,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", @@ -380,7 +386,9 @@ 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) }) @@ -388,6 +396,7 @@ func TestStaticModeCmdFlagValidation(t *testing.T) { } func TestProvisionerModeCmdFlagValidation(t *testing.T) { + t.Parallel() testCase := flagTestCase{ name: "valid flags", args: []string{ @@ -418,6 +427,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", @@ -450,7 +460,9 @@ 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) }) @@ -458,6 +470,7 @@ func TestSleepCmdFlagValidation(t *testing.T) { } func TestParseFlags(t *testing.T) { + t.Parallel() g := NewWithT(t) flagSet := pflag.NewFlagSet("flagSet", 0) diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 8761e3f1cd..435a0064c5 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -5,7 +5,7 @@ import ( "os" ) -// Set during go build +// Set during go build. var ( version string commit string diff --git a/cmd/gateway/validation.go b/cmd/gateway/validation.go index 2e3d60b3b7..8a064c29f8 100644 --- a/cmd/gateway/validation.go +++ b/cmd/gateway/validation.go @@ -163,7 +163,7 @@ func validateEndpoint(endpoint string) error { return fmt.Errorf("%q must be in the format :", endpoint) } -// validatePort makes sure a given port is inside the valid port range for its usage +// validatePort makes sure a given port is inside the valid port range for its usage. func validatePort(port int) error { if port < 1024 || port > 65535 { return fmt.Errorf("port outside of valid port range [1024 - 65535]: %v", port) @@ -171,7 +171,7 @@ func validatePort(port int) error { return nil } -// ensureNoPortCollisions checks if the same port has been defined multiple times +// ensureNoPortCollisions checks if the same port has been defined multiple times. func ensureNoPortCollisions(ports ...int) error { seen := make(map[int]struct{}) diff --git a/cmd/gateway/validation_test.go b/cmd/gateway/validation_test.go index f19e3ac84f..3b0e27369e 100644 --- a/cmd/gateway/validation_test.go +++ b/cmd/gateway/validation_test.go @@ -8,6 +8,7 @@ import ( ) func TestValidateGatewayControllerName(t *testing.T) { + t.Parallel() tests := []struct { name string value string @@ -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) @@ -66,6 +69,7 @@ func TestValidateGatewayControllerName(t *testing.T) { } func TestValidateResourceName(t *testing.T) { + t.Parallel() tests := []struct { name string value string @@ -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) @@ -129,6 +135,7 @@ func TestValidateResourceName(t *testing.T) { } func TestValidateNamespaceName(t *testing.T) { + t.Parallel() tests := []struct { name string value string @@ -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) @@ -192,6 +201,7 @@ func TestValidateNamespaceName(t *testing.T) { } func TestParseNamespacedResourceName(t *testing.T) { + t.Parallel() tests := []struct { name string value string @@ -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) @@ -256,6 +268,7 @@ func TestParseNamespacedResourceName(t *testing.T) { } func TestValidateQualifiedName(t *testing.T) { + t.Parallel() tests := []struct { name string value string @@ -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) @@ -318,6 +333,7 @@ func TestValidateQualifiedName(t *testing.T) { } func TestValidateURL(t *testing.T) { + t.Parallel() tests := []struct { name string url string @@ -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) @@ -380,6 +398,7 @@ func TestValidateURL(t *testing.T) { } func TestValidateIP(t *testing.T) { + t.Parallel() tests := []struct { name string expSubMsg string @@ -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) @@ -420,6 +441,7 @@ func TestValidateIP(t *testing.T) { } func TestValidateEndpoint(t *testing.T) { + t.Parallel() tests := []struct { name string endp string @@ -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) @@ -487,6 +511,7 @@ func TestValidateEndpoint(t *testing.T) { } func TestValidatePort(t *testing.T) { + t.Parallel() tests := []struct { name string port int @@ -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) @@ -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()) diff --git a/internal/framework/conditions/conditions_test.go b/internal/framework/conditions/conditions_test.go index 7bf69c271b..b446a6ecaf 100644 --- a/internal/framework/conditions/conditions_test.go +++ b/internal/framework/conditions/conditions_test.go @@ -8,6 +8,7 @@ import ( ) func TestDeduplicateConditions(t *testing.T) { + t.Parallel() conds := []Condition{ { Type: "Type1", @@ -61,6 +62,7 @@ func TestDeduplicateConditions(t *testing.T) { } func TestConvertConditions(t *testing.T) { + t.Parallel() conds := []Condition{ { Type: "Type1", diff --git a/internal/framework/controller/controller_suite_test.go b/internal/framework/controller/controller_suite_test.go index 2a0ef5ee0e..6e27263c66 100644 --- a/internal/framework/controller/controller_suite_test.go +++ b/internal/framework/controller/controller_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestControllers(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Controller Suite") } diff --git a/internal/framework/controller/filter/filter_test.go b/internal/framework/controller/filter/filter_test.go index d9638aeb8d..d250dd312e 100644 --- a/internal/framework/controller/filter/filter_test.go +++ b/internal/framework/controller/filter/filter_test.go @@ -8,6 +8,7 @@ import ( ) func TestCreateSingleResourceFilter(t *testing.T) { + t.Parallel() targetNsName := types.NamespacedName{Namespace: "test", Name: "resource"} g := NewWithT(t) @@ -50,7 +51,9 @@ func TestCreateSingleResourceFilter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) shouldProcess, msg := filter(test.nsname) g.Expect(shouldProcess).To(Equal(test.expectedShouldProcess)) diff --git a/internal/framework/controller/index/endpointslice_test.go b/internal/framework/controller/index/endpointslice_test.go index 23e09dbf41..6fb55411be 100644 --- a/internal/framework/controller/index/endpointslice_test.go +++ b/internal/framework/controller/index/endpointslice_test.go @@ -11,6 +11,7 @@ import ( ) func TestServiceNameIndexFunc(t *testing.T) { + t.Parallel() testcases := []struct { msg string obj client.Object @@ -49,6 +50,7 @@ func TestServiceNameIndexFunc(t *testing.T) { } func TestServiceNameIndexFuncPanics(t *testing.T) { + t.Parallel() defer func() { g := NewWithT(t) g.Expect(recover()).ToNot(BeNil()) diff --git a/internal/framework/controller/predicate/annotation_test.go b/internal/framework/controller/predicate/annotation_test.go index 6fe18b3a28..619b6e68aa 100644 --- a/internal/framework/controller/predicate/annotation_test.go +++ b/internal/framework/controller/predicate/annotation_test.go @@ -10,6 +10,7 @@ import ( ) func TestAnnotationPredicate_Create(t *testing.T) { + t.Parallel() annotation := "test" tests := []struct { @@ -58,7 +59,9 @@ func TestAnnotationPredicate_Create(t *testing.T) { p := AnnotationPredicate{Annotation: annotation} for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) update := p.Create(test.event) g.Expect(update).To(Equal(test.expUpdate)) @@ -67,6 +70,7 @@ func TestAnnotationPredicate_Create(t *testing.T) { } func TestAnnotationPredicate_Update(t *testing.T) { + t.Parallel() annotation := "test" tests := []struct { @@ -211,7 +215,9 @@ func TestAnnotationPredicate_Update(t *testing.T) { p := AnnotationPredicate{Annotation: annotation} for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) update := p.Update(test.event) g.Expect(update).To(Equal(test.expUpdate)) diff --git a/internal/framework/controller/predicate/gatewayclass_test.go b/internal/framework/controller/predicate/gatewayclass_test.go index e89d974f00..91d2bad8bd 100644 --- a/internal/framework/controller/predicate/gatewayclass_test.go +++ b/internal/framework/controller/predicate/gatewayclass_test.go @@ -9,6 +9,7 @@ import ( ) func TestGatewayClassPredicate(t *testing.T) { + t.Parallel() g := NewWithT(t) p := GatewayClassPredicate{ControllerName: "nginx-ctlr"} diff --git a/internal/framework/controller/predicate/service_test.go b/internal/framework/controller/predicate/service_test.go index 90bda2fd2d..7933ac5c8b 100644 --- a/internal/framework/controller/predicate/service_test.go +++ b/internal/framework/controller/predicate/service_test.go @@ -13,6 +13,7 @@ import ( ) func TestServicePortsChangedPredicate_Update(t *testing.T) { + t.Parallel() testcases := []struct { objectOld client.Object objectNew client.Object @@ -227,7 +228,9 @@ func TestServicePortsChangedPredicate_Update(t *testing.T) { p := ServicePortsChangedPredicate{} for _, tc := range testcases { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) update := p.Update(event.UpdateEvent{ ObjectOld: tc.objectOld, @@ -240,6 +243,7 @@ func TestServicePortsChangedPredicate_Update(t *testing.T) { } func TestServicePortsChangedPredicate(t *testing.T) { + t.Parallel() g := NewWithT(t) p := GatewayServicePredicate{} @@ -250,6 +254,7 @@ func TestServicePortsChangedPredicate(t *testing.T) { } func TestGatewayServicePredicate_Update(t *testing.T) { + t.Parallel() testcases := []struct { objectOld client.Object objectNew client.Object @@ -440,7 +445,9 @@ func TestGatewayServicePredicate_Update(t *testing.T) { p := GatewayServicePredicate{NSName: types.NamespacedName{Namespace: "nginx-gateway", Name: "nginx"}} for _, tc := range testcases { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) update := p.Update(event.UpdateEvent{ ObjectOld: tc.objectOld, @@ -453,6 +460,7 @@ func TestGatewayServicePredicate_Update(t *testing.T) { } func TestGatewayServicePredicate(t *testing.T) { + t.Parallel() g := NewWithT(t) p := GatewayServicePredicate{} diff --git a/internal/framework/controller/register_test.go b/internal/framework/controller/register_test.go index 3f6f01fe21..37f5d07c76 100644 --- a/internal/framework/controller/register_test.go +++ b/internal/framework/controller/register_test.go @@ -27,6 +27,7 @@ import ( ) func TestRegister(t *testing.T) { + t.Parallel() type fakes struct { mgr *controllerfakes.FakeManager indexer *controllerfakes.FakeFieldIndexer @@ -120,7 +121,9 @@ func TestRegister(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) newReconciler := func(c controller.ReconcilerConfig) *controller.Reconciler { diff --git a/internal/framework/events/events_suite_test.go b/internal/framework/events/events_suite_test.go index 1c318a89b4..d2b8ee906d 100644 --- a/internal/framework/events/events_suite_test.go +++ b/internal/framework/events/events_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestEvents(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Events Suite") } diff --git a/internal/framework/events/events_test.go b/internal/framework/events/events_test.go index e36b539456..6ed5ce8b54 100644 --- a/internal/framework/events/events_test.go +++ b/internal/framework/events/events_test.go @@ -8,6 +8,7 @@ import ( ) func TestEventLoop_SwapBatches(t *testing.T) { + t.Parallel() g := NewWithT(t) eventLoop := NewEventLoop(nil, zap.New(), nil, nil) diff --git a/internal/framework/gatewayclass/validate_test.go b/internal/framework/gatewayclass/validate_test.go index 8359365477..d8def4964c 100644 --- a/internal/framework/gatewayclass/validate_test.go +++ b/internal/framework/gatewayclass/validate_test.go @@ -13,6 +13,7 @@ import ( ) func TestValidateCRDVersions(t *testing.T) { + t.Parallel() createCRDMetadata := func(version string) *metav1.PartialObjectMetadata { return &metav1.PartialObjectMetadata{ ObjectMeta: metav1.ObjectMeta{ @@ -113,7 +114,9 @@ func TestValidateCRDVersions(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) conds, valid := gatewayclass.ValidateCRDVersions(test.crds) diff --git a/internal/framework/helpers/helpers_test.go b/internal/framework/helpers/helpers_test.go index fbd1498b0b..0c4b598a8a 100644 --- a/internal/framework/helpers/helpers_test.go +++ b/internal/framework/helpers/helpers_test.go @@ -13,6 +13,7 @@ import ( ) func TestMustCastObject(t *testing.T) { + t.Parallel() g := NewWithT(t) var obj client.Object = &gatewayv1.Gateway{} @@ -27,6 +28,7 @@ func TestMustCastObject(t *testing.T) { } func TestEqualPointers(t *testing.T) { + t.Parallel() tests := []struct { p1 *string p2 *string @@ -78,7 +80,9 @@ func TestEqualPointers(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) val := helpers.EqualPointers(test.p1, test.p2) @@ -88,6 +92,7 @@ func TestEqualPointers(t *testing.T) { } func TestMustExecuteTemplate(t *testing.T) { + t.Parallel() g := NewWithT(t) tmpl := template.Must(template.New("test").Parse(`Hello {{.}}`)) @@ -96,6 +101,7 @@ func TestMustExecuteTemplate(t *testing.T) { } func TestMustExecuteTemplatePanics(t *testing.T) { + t.Parallel() g := NewWithT(t) execute := func() { diff --git a/internal/framework/kinds/kinds.go b/internal/framework/kinds/kinds.go index 790ae4eabc..f5efa38187 100644 --- a/internal/framework/kinds/kinds.go +++ b/internal/framework/kinds/kinds.go @@ -9,9 +9,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client/apiutil" ) -// Gateway API Kinds +// Gateway API Kinds. const ( - // Gateway is the Gateway Kind + // Gateway is the Gateway Kind. Gateway = "Gateway" // GatewayClass is the GatewayClass Kind. GatewayClass = "GatewayClass" diff --git a/internal/framework/runnables/cronjob.go b/internal/framework/runnables/cronjob.go index 3bd4f32eaf..d9c2eaf631 100644 --- a/internal/framework/runnables/cronjob.go +++ b/internal/framework/runnables/cronjob.go @@ -37,7 +37,7 @@ func NewCronJob(cfg CronJobConfig) *CronJob { } // Start starts the cronjob. -// Implements controller-runtime manager.Runnable +// Implements controller-runtime manager.Runnable. func (j *CronJob) Start(ctx context.Context) error { select { case <-j.cfg.ReadyCh: diff --git a/internal/framework/runnables/cronjob_test.go b/internal/framework/runnables/cronjob_test.go index ca1154c30a..310ceef618 100644 --- a/internal/framework/runnables/cronjob_test.go +++ b/internal/framework/runnables/cronjob_test.go @@ -10,6 +10,7 @@ import ( ) func TestCronJob(t *testing.T) { + t.Parallel() g := NewWithT(t) readyChannel := make(chan struct{}) @@ -50,6 +51,7 @@ func TestCronJob(t *testing.T) { } func TestCronJob_ContextCanceled(t *testing.T) { + t.Parallel() g := NewWithT(t) readyChannel := make(chan struct{}) diff --git a/internal/framework/runnables/runnables_test.go b/internal/framework/runnables/runnables_test.go index 28af829306..9f34d9ccba 100644 --- a/internal/framework/runnables/runnables_test.go +++ b/internal/framework/runnables/runnables_test.go @@ -8,6 +8,7 @@ import ( ) func TestLeader(t *testing.T) { + t.Parallel() leader := &Leader{} g := NewWithT(t) @@ -15,6 +16,7 @@ func TestLeader(t *testing.T) { } func TestLeaderOrNonLeader(t *testing.T) { + t.Parallel() leaderOrNonLeader := &LeaderOrNonLeader{} g := NewWithT(t) @@ -22,6 +24,7 @@ func TestLeaderOrNonLeader(t *testing.T) { } func TestEnableAfterBecameLeader(t *testing.T) { + t.Parallel() enabled := false enableAfterBecameLeader := NewEnableAfterBecameLeader(func(_ context.Context) { enabled = true diff --git a/internal/framework/status/conditions_test.go b/internal/framework/status/conditions_test.go index c3d788e69d..838e068019 100644 --- a/internal/framework/status/conditions_test.go +++ b/internal/framework/status/conditions_test.go @@ -9,6 +9,7 @@ import ( ) func TestConditionsEqual(t *testing.T) { + t.Parallel() getDefaultConds := func() []v1.Condition { return []v1.Condition{ { @@ -110,7 +111,9 @@ func TestConditionsEqual(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) equal := ConditionsEqual(test.prevConds, test.curConds) g.Expect(equal).To(Equal(test.expEqual)) diff --git a/internal/framework/status/status_suite_test.go b/internal/framework/status/status_suite_test.go index b2dad44818..9dae71aec2 100644 --- a/internal/framework/status/status_suite_test.go +++ b/internal/framework/status/status_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestStatus(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Status Suite") } diff --git a/internal/framework/status/updater_retry_test.go b/internal/framework/status/updater_retry_test.go index 69a8b5e388..5c6fa67b05 100644 --- a/internal/framework/status/updater_retry_test.go +++ b/internal/framework/status/updater_retry_test.go @@ -19,6 +19,7 @@ import ( ) func TestNewRetryUpdateFunc(t *testing.T) { + t.Parallel() tests := []struct { getReturns error updateReturns error @@ -70,7 +71,9 @@ func TestNewRetryUpdateFunc(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) fakeStatusUpdater := &statusfakes.FakeK8sUpdater{} diff --git a/internal/mode/provisioner/provisioner_suite_test.go b/internal/mode/provisioner/provisioner_suite_test.go index 6cfdb4144c..1435a2230e 100644 --- a/internal/mode/provisioner/provisioner_suite_test.go +++ b/internal/mode/provisioner/provisioner_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestProvisioner(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Provisioner Suite") } diff --git a/internal/mode/static/config_updater_test.go b/internal/mode/static/config_updater_test.go index ee44971950..298c16a13b 100644 --- a/internal/mode/static/config_updater_test.go +++ b/internal/mode/static/config_updater_test.go @@ -16,6 +16,7 @@ import ( ) func TestUpdateControlPlane(t *testing.T) { + t.Parallel() debugLogCfg := &ngfAPI.NginxGateway{ Spec: ngfAPI.NginxGatewaySpec{ Logging: &ngfAPI.Logging{ @@ -71,7 +72,9 @@ func TestUpdateControlPlane(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) fakeLogSetter := &staticfakes.FakeLogLevelSetter{ @@ -103,6 +106,7 @@ func TestUpdateControlPlane(t *testing.T) { } func TestValidateLogLevel(t *testing.T) { + t.Parallel() validLevels := []ngfAPI.ControllerLogLevel{ ngfAPI.ControllerLogLevelError, ngfAPI.ControllerLogLevelInfo, @@ -116,7 +120,9 @@ func TestValidateLogLevel(t *testing.T) { } for _, level := range validLevels { + level := level t.Run(fmt.Sprintf("valid level %q", level), func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(validateLogLevel(level)).To(Succeed()) @@ -124,7 +130,9 @@ func TestValidateLogLevel(t *testing.T) { } for _, level := range invalidLevels { + level := level t.Run(fmt.Sprintf("invalid level %q", level), func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(validateLogLevel(level)).ToNot(Succeed()) diff --git a/internal/mode/static/handler.go b/internal/mode/static/handler.go index 2dfcbb2e56..fd76e7536b 100644 --- a/internal/mode/static/handler.go +++ b/internal/mode/static/handler.go @@ -89,7 +89,7 @@ type eventHandlerConfig struct { } const ( - // groups for GroupStatusUpdater + // groups for GroupStatusUpdater. groupAllExceptGateways = "all-graphs-except-gateways" groupGateways = "gateways" groupControlPlane = "control-plane" @@ -308,7 +308,7 @@ func (h *eventHandlerImpl) parseAndCaptureEvent(ctx context.Context, logger logr } } -// updateNginxConf updates nginx conf files and reloads nginx +// updateNginxConf updates nginx conf files and reloads nginx. func (h *eventHandlerImpl) updateNginxConf(ctx context.Context, conf dataplane.Configuration) error { files := h.cfg.generator.Generate(conf) if err := h.cfg.nginxFileMgr.ReplaceFiles(files); err != nil { @@ -324,7 +324,7 @@ func (h *eventHandlerImpl) updateNginxConf(ctx context.Context, conf dataplane.C // updateUpstreamServers is called only when endpoints have changed. It updates nginx conf files and then: // - if using NGINX Plus, determines which servers have changed and uses the N+ API to update them; -// - otherwise if not using NGINX Plus, or an error was returned from the API, reloads nginx +// - otherwise if not using NGINX Plus, or an error was returned from the API, reloads nginx. func (h *eventHandlerImpl) updateUpstreamServers( ctx context.Context, logger logr.Logger, @@ -410,7 +410,7 @@ func serversEqual(newServers []ngxclient.UpstreamServer, oldServers []ngxclient. } // updateControlPlaneAndSetStatus updates the control plane configuration and then sets the status -// based on the outcome +// based on the outcome. func (h *eventHandlerImpl) updateControlPlaneAndSetStatus( ctx context.Context, logger logr.Logger, diff --git a/internal/mode/static/health_test.go b/internal/mode/static/health_test.go index 352cc50b3c..5bfd7aab73 100644 --- a/internal/mode/static/health_test.go +++ b/internal/mode/static/health_test.go @@ -7,6 +7,7 @@ import ( ) func TestReadyCheck(t *testing.T) { + t.Parallel() g := NewWithT(t) nginxChecker := newNginxConfiguredOnStartChecker() g.Expect(nginxChecker.readyCheck(nil)).ToNot(Succeed()) diff --git a/internal/mode/static/log_level_setters_test.go b/internal/mode/static/log_level_setters_test.go index 214b9a15bc..df2d51f447 100644 --- a/internal/mode/static/log_level_setters_test.go +++ b/internal/mode/static/log_level_setters_test.go @@ -11,6 +11,7 @@ import ( ) func TestMultiLogLevelSetter_SetLevel(t *testing.T) { + t.Parallel() g := NewWithT(t) logr1 := &staticfakes.FakeLogLevelSetter{} @@ -41,6 +42,7 @@ func TestMultiLogLevelSetter_SetLevel(t *testing.T) { } func TestZapLogLevelSetter_SetLevel(t *testing.T) { + t.Parallel() g := NewWithT(t) zapSetter := newZapLogLevelSetter(zap.NewAtomicLevel()) @@ -58,6 +60,7 @@ func TestZapLogLevelSetter_SetLevel(t *testing.T) { } func TestPromLogLevelSetter_SetLevel(t *testing.T) { + t.Parallel() g := NewWithT(t) logger, err := newLeveledPrometheusLogger() diff --git a/internal/mode/static/manager.go b/internal/mode/static/manager.go index f3b92ad076..1d52bbf20b 100644 --- a/internal/mode/static/manager.go +++ b/internal/mode/static/manager.go @@ -62,7 +62,7 @@ import ( ) const ( - // clusterTimeout is a timeout for connections to the Kubernetes API + // clusterTimeout is a timeout for connections to the Kubernetes API. clusterTimeout = 10 * time.Second ) @@ -529,7 +529,7 @@ func registerControllers( } // 10 min jitter is enough per telemetry destination recommendation -// For the default period of 24 hours, jitter will be 10min /(24*60)min = 0.0069 +// For the default period of 24 hours, jitter will be 10min /(24*60)min = 0.0069. const telemetryJitterFactor = 10.0 / (24 * 60) // added jitter is bound by jitterFactor * period func createTelemetryJob( diff --git a/internal/mode/static/manager_test.go b/internal/mode/static/manager_test.go index 73cfa7be26..32d6005159 100644 --- a/internal/mode/static/manager_test.go +++ b/internal/mode/static/manager_test.go @@ -21,6 +21,7 @@ import ( ) func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) { + t.Parallel() const gcName = "nginx" partialObjectMetadataList := &metav1.PartialObjectMetadataList{} @@ -114,7 +115,9 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) objects, objectLists := prepareFirstEventBatchPreparerArgs(gcName, test.gwNsName, test.experimentalEnabled) @@ -126,6 +129,7 @@ func TestPrepareFirstEventBatchPreparerArgs(t *testing.T) { } func TestGetMetricsOptions(t *testing.T) { + t.Parallel() tests := []struct { name string expectedOptions metricsserver.Options @@ -163,7 +167,9 @@ func TestGetMetricsOptions(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) metricsServerOptions := getMetricsOptions(test.metricsConfig) diff --git a/internal/mode/static/metrics/collectors/controller.go b/internal/mode/static/metrics/collectors/controller.go index d578786601..fa1f9757ef 100644 --- a/internal/mode/static/metrics/collectors/controller.go +++ b/internal/mode/static/metrics/collectors/controller.go @@ -15,7 +15,7 @@ type ControllerCollector struct { eventBatchProcessDuration prometheus.Histogram } -// NewControllerCollector creates a new ControllerCollector +// NewControllerCollector creates a new ControllerCollector. func NewControllerCollector(constLabels map[string]string) *ControllerCollector { nc := &ControllerCollector{ eventBatchProcessDuration: prometheus.NewHistogram( diff --git a/internal/mode/static/metrics/collectors/nginx.go b/internal/mode/static/metrics/collectors/nginx.go index 87d8039e22..28cbc635d3 100644 --- a/internal/mode/static/metrics/collectors/nginx.go +++ b/internal/mode/static/metrics/collectors/nginx.go @@ -16,7 +16,7 @@ const ( nginxStatusURI = "http://config-status/stub_status" ) -// NewNginxMetricsCollector creates an NginxCollector which fetches stats from NGINX over a unix socket +// NewNginxMetricsCollector creates an NginxCollector which fetches stats from NGINX over a unix socket. func NewNginxMetricsCollector(constLabels map[string]string, logger log.Logger) prometheus.Collector { httpClient := runtime.GetSocketClient(nginxStatusSock) ngxClient := prometheusClient.NewNginxClient(&httpClient, nginxStatusURI) @@ -24,7 +24,7 @@ func NewNginxMetricsCollector(constLabels map[string]string, logger log.Logger) return nginxCollector.NewNginxCollector(ngxClient, metrics.Namespace, constLabels, logger) } -// NewNginxPlusMetricsCollector creates an NginxCollector which fetches stats from NGINX Plus API over a unix socket +// NewNginxPlusMetricsCollector creates an NginxCollector which fetches stats from NGINX Plus API over a unix socket. func NewNginxPlusMetricsCollector( plusClient *client.NginxClient, constLabels map[string]string, diff --git a/internal/mode/static/metrics/collectors/nginx_runtime.go b/internal/mode/static/metrics/collectors/nginx_runtime.go index 4f57cca61d..5195e603d6 100644 --- a/internal/mode/static/metrics/collectors/nginx_runtime.go +++ b/internal/mode/static/metrics/collectors/nginx_runtime.go @@ -8,7 +8,7 @@ import ( "github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/metrics" ) -// NginxRuntimeCollector implements runtime.Collector interface and prometheus.Collector interface +// NginxRuntimeCollector implements runtime.Collector interface and prometheus.Collector interface. type NginxRuntimeCollector struct { // Metrics reloadsTotal prometheus.Counter @@ -17,7 +17,7 @@ type NginxRuntimeCollector struct { reloadsDuration prometheus.Histogram } -// NewManagerMetricsCollector creates a new NginxRuntimeCollector +// NewManagerMetricsCollector creates a new NginxRuntimeCollector. func NewManagerMetricsCollector(constLabels map[string]string) *NginxRuntimeCollector { nc := &NginxRuntimeCollector{ reloadsTotal: prometheus.NewCounter( diff --git a/internal/mode/static/nginx/config/base_http_config_test.go b/internal/mode/static/nginx/config/base_http_config_test.go index 2f609d8409..4e2ce5a975 100644 --- a/internal/mode/static/nginx/config/base_http_config_test.go +++ b/internal/mode/static/nginx/config/base_http_config_test.go @@ -10,6 +10,7 @@ import ( ) func TestExecuteBaseHttp(t *testing.T) { + t.Parallel() confOn := dataplane.Configuration{ BaseHTTPConfig: dataplane.BaseHTTPConfig{ HTTP2: true, diff --git a/internal/mode/static/nginx/config/convert_test.go b/internal/mode/static/nginx/config/convert_test.go index c755f2c3c9..cfce680f89 100644 --- a/internal/mode/static/nginx/config/convert_test.go +++ b/internal/mode/static/nginx/config/convert_test.go @@ -10,6 +10,7 @@ import ( ) func TestConvertEndpoints(t *testing.T) { + t.Parallel() endpoints := []resolver.Endpoint{ { Address: "1.2.3.4", diff --git a/internal/mode/static/nginx/config/generator_test.go b/internal/mode/static/nginx/config/generator_test.go index d4e6a5f841..2345c87e9c 100644 --- a/internal/mode/static/nginx/config/generator_test.go +++ b/internal/mode/static/nginx/config/generator_test.go @@ -14,6 +14,7 @@ import ( ) func TestGenerate(t *testing.T) { + t.Parallel() bg := dataplane.BackendGroup{ Source: types.NamespacedName{Namespace: "test", Name: "hr"}, RuleIdx: 0, diff --git a/internal/mode/static/nginx/config/maps.go b/internal/mode/static/nginx/config/maps.go index 97f5486a98..a784390170 100644 --- a/internal/mode/static/nginx/config/maps.go +++ b/internal/mode/static/nginx/config/maps.go @@ -48,7 +48,7 @@ func buildAddHeaderMaps(servers []dataplane.VirtualServer) []http.Map { const ( // In order to prepend any passed client header values to values specified in the add headers field of request - // header modifiers, we need to create a map parameter regex for any string value + // header modifiers, we need to create a map parameter regex for any string value. anyStringFmt = `~.*` ) diff --git a/internal/mode/static/nginx/config/maps_test.go b/internal/mode/static/nginx/config/maps_test.go index e903c17151..1ff3b1637c 100644 --- a/internal/mode/static/nginx/config/maps_test.go +++ b/internal/mode/static/nginx/config/maps_test.go @@ -11,6 +11,7 @@ import ( ) func TestExecuteMaps(t *testing.T) { + t.Parallel() g := NewWithT(t) pathRules := []dataplane.PathRule{ { @@ -98,6 +99,7 @@ func TestExecuteMaps(t *testing.T) { } func TestBuildAddHeaderMaps(t *testing.T) { + t.Parallel() g := NewWithT(t) pathRules := []dataplane.PathRule{ { diff --git a/internal/mode/static/nginx/config/servers.go b/internal/mode/static/nginx/config/servers.go index cc385449a4..54bbe709ed 100644 --- a/internal/mode/static/nginx/config/servers.go +++ b/internal/mode/static/nginx/config/servers.go @@ -21,7 +21,7 @@ const ( rootPath = "/" ) -// httpBaseHeaders contains the constant headers set in each HTTP server block +// httpBaseHeaders contains the constant headers set in each HTTP server block. var httpBaseHeaders = []http.Header{ { Name: "Host", @@ -41,7 +41,7 @@ var httpBaseHeaders = []http.Header{ }, } -// grpcBaseHeaders contains the constant headers set in each gRPC server block +// grpcBaseHeaders contains the constant headers set in each gRPC server block. var grpcBaseHeaders = []http.Header{ { Name: "Host", @@ -203,7 +203,7 @@ func createServer(virtualServer dataplane.VirtualServer, serverID int) (http.Ser } // rewriteConfig contains the configuration for a location to rewrite paths, -// as specified in a URLRewrite filter +// as specified in a URLRewrite filter. type rewriteConfig struct { // Rewrite rewrites the original URI to the new URI (ex: /coffee -> /beans) Rewrite string @@ -284,7 +284,7 @@ func updateLocationsForIncludes(locations []http.Location, includes []string) [] } // pathAndTypeMap contains a map of paths and any path types defined for that path -// for example, {/foo: {exact: {}, prefix: {}}} +// for example, {/foo: {exact: {}, prefix: {}}}. type pathAndTypeMap map[string]map[dataplane.PathType]struct{} // To calculate the maximum number of locations, we need to take into account the following: @@ -759,7 +759,7 @@ func createDefaultRootLocation() http.Location { } } -// isNonSlashedPrefixPath returns whether or not a path is of type Prefix and does not contain a trailing slash +// isNonSlashedPrefixPath returns whether or not a path is of type Prefix and does not contain a trailing slash. func isNonSlashedPrefixPath(pathType dataplane.PathType, path string) bool { return pathType == dataplane.PathTypePrefix && !strings.HasSuffix(path, "/") } diff --git a/internal/mode/static/nginx/config/servers_test.go b/internal/mode/static/nginx/config/servers_test.go index ae458e8f03..a9a27823fc 100644 --- a/internal/mode/static/nginx/config/servers_test.go +++ b/internal/mode/static/nginx/config/servers_test.go @@ -15,6 +15,7 @@ import ( ) func TestExecuteServers(t *testing.T) { + t.Parallel() conf := dataplane.Configuration{ HTTPServers: []dataplane.VirtualServer{ { @@ -138,6 +139,7 @@ func TestExecuteServers(t *testing.T) { } func TestExecuteForDefaultServers(t *testing.T) { + t.Parallel() testcases := []struct { msg string httpPorts []int @@ -205,7 +207,9 @@ func TestExecuteForDefaultServers(t *testing.T) { httpDefaultFmt := "listen %d default_server" for _, tc := range testcases { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) serverResults := executeServers(tc.conf) @@ -226,6 +230,7 @@ func TestExecuteForDefaultServers(t *testing.T) { } func TestCreateServers(t *testing.T) { + t.Parallel() const ( sslKeyPairID = "test-keypair" ) @@ -1075,6 +1080,7 @@ func modifyMatchPairs(matchPairs httpMatchPairs) httpMatchPairs { } func TestCreateServersConflicts(t *testing.T) { + t.Parallel() fooGroup := dataplane.BackendGroup{ Source: types.NamespacedName{Namespace: "test", Name: "route"}, RuleIdx: 0, @@ -1241,7 +1247,9 @@ func TestCreateServersConflicts(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() httpServers := []dataplane.VirtualServer{ { IsDefault: true, @@ -1274,6 +1282,7 @@ func TestCreateServersConflicts(t *testing.T) { } func TestCreateLocationsRootPath(t *testing.T) { + t.Parallel() hrNsName := types.NamespacedName{Namespace: "test", Name: "route1"} fooGroup := dataplane.BackendGroup{ @@ -1431,7 +1440,9 @@ func TestCreateLocationsRootPath(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) locs, httpMatchPair, grpc := createLocations(&dataplane.VirtualServer{ @@ -1446,6 +1457,7 @@ func TestCreateLocationsRootPath(t *testing.T) { } func TestCreateReturnValForRedirectFilter(t *testing.T) { + t.Parallel() const listenerPortCustom = 123 const listenerPortHTTP = 80 const listenerPortHTTPS = 443 @@ -1567,7 +1579,9 @@ func TestCreateReturnValForRedirectFilter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := createReturnValForRedirectFilter(test.filter, test.listenerPort) @@ -1577,6 +1591,7 @@ func TestCreateReturnValForRedirectFilter(t *testing.T) { } func TestCreateRewritesValForRewriteFilter(t *testing.T) { + t.Parallel() tests := []struct { filter *dataplane.HTTPURLRewriteFilter expected *rewriteConfig @@ -1686,7 +1701,9 @@ func TestCreateRewritesValForRewriteFilter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := createRewritesValForRewriteFilter(test.filter, test.path) @@ -1696,6 +1713,7 @@ func TestCreateRewritesValForRewriteFilter(t *testing.T) { } func TestCreateRouteMatch(t *testing.T) { + t.Parallel() testPath := "/internal_loc" testMethodMatch := helpers.GetPointer("PUT") @@ -1845,7 +1863,9 @@ func TestCreateRouteMatch(t *testing.T) { }, } for _, tc := range tests { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := createRouteMatch(tc.match, testPath) @@ -1855,6 +1875,7 @@ func TestCreateRouteMatch(t *testing.T) { } func TestCreateQueryParamKeyValString(t *testing.T) { + t.Parallel() g := NewWithT(t) expected := "key=value" @@ -1881,6 +1902,7 @@ func TestCreateQueryParamKeyValString(t *testing.T) { } func TestCreateHeaderKeyValString(t *testing.T) { + t.Parallel() g := NewWithT(t) expected := "kEy:vALUe" @@ -1896,6 +1918,7 @@ func TestCreateHeaderKeyValString(t *testing.T) { } func TestIsPathOnlyMatch(t *testing.T) { + t.Parallel() tests := []struct { msg string match dataplane.Match @@ -1940,7 +1963,9 @@ func TestIsPathOnlyMatch(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := isPathOnlyMatch(tc.match) @@ -1950,6 +1975,7 @@ func TestIsPathOnlyMatch(t *testing.T) { } func TestCreateProxyPass(t *testing.T) { + t.Parallel() g := NewWithT(t) tests := []struct { @@ -2025,6 +2051,7 @@ func TestCreateProxyPass(t *testing.T) { } func TestCreateMatchLocation(t *testing.T) { + t.Parallel() g := NewWithT(t) expected := http.Location{ @@ -2036,6 +2063,7 @@ func TestCreateMatchLocation(t *testing.T) { } func TestGenerateProxySetHeaders(t *testing.T) { + t.Parallel() tests := []struct { filters *dataplane.HTTPFilters msg string @@ -2180,7 +2208,9 @@ func TestGenerateProxySetHeaders(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) headers := generateProxySetHeaders(tc.filters, tc.GRPC) @@ -2190,7 +2220,7 @@ func TestGenerateProxySetHeaders(t *testing.T) { } func TestConvertBackendTLSFromGroup(t *testing.T) { - g := NewWithT(t) + t.Parallel() tests := []struct { expected *http.ProxySSLVerify @@ -2271,7 +2301,10 @@ func TestConvertBackendTLSFromGroup(t *testing.T) { } for _, tc := range tests { - t.Run(tc.msg, func(_ *testing.T) { + tc := tc + t.Run(tc.msg, func(t *testing.T) { + t.Parallel() + g := NewWithT(t) result := createProxyTLSFromBackends(tc.grp) g.Expect(result).To(Equal(tc.expected)) }) @@ -2279,6 +2312,7 @@ func TestConvertBackendTLSFromGroup(t *testing.T) { } func TestGenerateResponseHeaders(t *testing.T) { + t.Parallel() tests := []struct { filters *dataplane.HTTPFilters msg string @@ -2337,7 +2371,9 @@ func TestGenerateResponseHeaders(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) headers := generateResponseHeaders(tc.filters) @@ -2347,6 +2383,7 @@ func TestGenerateResponseHeaders(t *testing.T) { } func TestCreateIncludes(t *testing.T) { + t.Parallel() tests := []struct { name string additions []dataplane.Addition @@ -2382,7 +2419,9 @@ func TestCreateIncludes(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) includes := createIncludes(test.additions) @@ -2392,6 +2431,7 @@ func TestCreateIncludes(t *testing.T) { } func TestCreateAdditionFileResults(t *testing.T) { + t.Parallel() conf := dataplane.Configuration{ HTTPServers: []dataplane.VirtualServer{ { @@ -2510,6 +2550,7 @@ func TestCreateAdditionFileResults(t *testing.T) { } func TestAdditionFilename(t *testing.T) { + t.Parallel() g := NewWithT(t) name := createAdditionFileName(dataplane.Addition{Identifier: "my-addition"}) diff --git a/internal/mode/static/nginx/config/split_clients.go b/internal/mode/static/nginx/config/split_clients.go index 0cc050e7c0..dd2b6958e0 100644 --- a/internal/mode/static/nginx/config/split_clients.go +++ b/internal/mode/static/nginx/config/split_clients.go @@ -117,7 +117,7 @@ func getSplitClientValue(b dataplane.Backend) string { // The percentage is rounded to 2 decimal places using the Floor method. // Floor is used here in order to guarantee that the sum of all percentages does not exceed 100. // Ex. percentOf(2, 3) = 66.66 -// Ex. percentOf(800, 2000) = 40.00 +// Ex. percentOf(800, 2000) = 40.00. func percentOf(weight, totalWeight int32) float64 { p := (float64(weight) * 100) / float64(totalWeight) return math.Floor(p*100) / 100 diff --git a/internal/mode/static/nginx/config/split_clients_test.go b/internal/mode/static/nginx/config/split_clients_test.go index 9ee6785ca9..95d8423493 100644 --- a/internal/mode/static/nginx/config/split_clients_test.go +++ b/internal/mode/static/nginx/config/split_clients_test.go @@ -11,6 +11,7 @@ import ( ) func TestExecuteSplitClients(t *testing.T) { + t.Parallel() bg1 := dataplane.BackendGroup{ Source: types.NamespacedName{Namespace: "test", Name: "hr"}, RuleIdx: 0, @@ -96,7 +97,9 @@ func TestExecuteSplitClients(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) splitResults := executeSplitClients(dataplane.Configuration{BackendGroups: test.backendGroups}) g.Expect(splitResults).To(HaveLen(1)) @@ -115,6 +118,7 @@ func TestExecuteSplitClients(t *testing.T) { } func TestCreateSplitClients(t *testing.T) { + t.Parallel() hrNoSplit := types.NamespacedName{Namespace: "test", Name: "hr-no-split"} hrOneSplit := types.NamespacedName{Namespace: "test", Name: "hr-one-split"} hrTwoSplits := types.NamespacedName{Namespace: "test", Name: "hr-two-splits"} @@ -240,7 +244,9 @@ func TestCreateSplitClients(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := createSplitClients(test.backendGroups) g.Expect(result).To(Equal(test.expSplitClients)) @@ -249,6 +255,7 @@ func TestCreateSplitClients(t *testing.T) { } func TestCreateSplitClientDistributions(t *testing.T) { + t.Parallel() tests := []struct { msg string backends []dataplane.Backend @@ -387,7 +394,9 @@ func TestCreateSplitClientDistributions(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := createSplitClientDistributions(dataplane.BackendGroup{Backends: test.backends}) g.Expect(result).To(Equal(test.expDistributions)) @@ -396,6 +405,7 @@ func TestCreateSplitClientDistributions(t *testing.T) { } func TestGetSplitClientValue(t *testing.T) { + t.Parallel() tests := []struct { msg string expValue string @@ -420,7 +430,9 @@ func TestGetSplitClientValue(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := getSplitClientValue(test.backend) g.Expect(result).To(Equal(test.expValue)) @@ -429,6 +441,7 @@ func TestGetSplitClientValue(t *testing.T) { } func TestPercentOf(t *testing.T) { + t.Parallel() tests := []struct { msg string weight int32 @@ -492,7 +505,9 @@ func TestPercentOf(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) percent := percentOf(test.weight, test.totalWeight) g.Expect(percent).To(Equal(test.expPercent)) @@ -501,6 +516,7 @@ func TestPercentOf(t *testing.T) { } func TestBackendGroupNeedsSplit(t *testing.T) { + t.Parallel() tests := []struct { msg string backends []dataplane.Backend @@ -573,7 +589,9 @@ func TestBackendGroupNeedsSplit(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) bg := dataplane.BackendGroup{ Source: types.NamespacedName{Namespace: "test", Name: "hr"}, @@ -586,6 +604,7 @@ func TestBackendGroupNeedsSplit(t *testing.T) { } func TestBackendGroupName(t *testing.T) { + t.Parallel() tests := []struct { msg string expName string @@ -669,7 +688,9 @@ func TestBackendGroupName(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) bg := dataplane.BackendGroup{ Source: types.NamespacedName{Namespace: "test", Name: "hr"}, diff --git a/internal/mode/static/nginx/config/telemetry_test.go b/internal/mode/static/nginx/config/telemetry_test.go index 6d59c1abac..5838152985 100644 --- a/internal/mode/static/nginx/config/telemetry_test.go +++ b/internal/mode/static/nginx/config/telemetry_test.go @@ -10,6 +10,7 @@ import ( ) func TestExecuteTelemetry(t *testing.T) { + t.Parallel() conf := dataplane.Configuration{ Telemetry: dataplane.Telemetry{ Endpoint: "1.2.3.4:123", @@ -50,6 +51,7 @@ func TestExecuteTelemetry(t *testing.T) { } func TestExecuteTelemetryNil(t *testing.T) { + t.Parallel() conf := dataplane.Configuration{ Telemetry: dataplane.Telemetry{}, } diff --git a/internal/mode/static/nginx/config/upstreams_test.go b/internal/mode/static/nginx/config/upstreams_test.go index 8f8c6a2e58..36b9744a01 100644 --- a/internal/mode/static/nginx/config/upstreams_test.go +++ b/internal/mode/static/nginx/config/upstreams_test.go @@ -11,6 +11,7 @@ import ( ) func TestExecuteUpstreams(t *testing.T) { + t.Parallel() gen := GeneratorImpl{} stateUpstreams := []dataplane.Upstream{ { @@ -59,6 +60,7 @@ func TestExecuteUpstreams(t *testing.T) { } func TestCreateUpstreams(t *testing.T) { + t.Parallel() gen := GeneratorImpl{} stateUpstreams := []dataplane.Upstream{ { @@ -143,6 +145,7 @@ func TestCreateUpstreams(t *testing.T) { } func TestCreateUpstream(t *testing.T) { + t.Parallel() gen := GeneratorImpl{} tests := []struct { msg string @@ -219,7 +222,9 @@ func TestCreateUpstream(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := gen.createUpstream(test.stateUpstream) g.Expect(result).To(Equal(test.expectedUpstream)) @@ -228,6 +233,7 @@ func TestCreateUpstream(t *testing.T) { } func TestCreateUpstreamPlus(t *testing.T) { + t.Parallel() gen := GeneratorImpl{plus: true} stateUpstream := dataplane.Upstream{ diff --git a/internal/mode/static/nginx/config/validation/common_test.go b/internal/mode/static/nginx/config/validation/common_test.go index f7c2f3be74..da3059e4c4 100644 --- a/internal/mode/static/nginx/config/validation/common_test.go +++ b/internal/mode/static/nginx/config/validation/common_test.go @@ -6,6 +6,7 @@ import ( ) func TestValidateEscapedString(t *testing.T) { + t.Parallel() validator := func(value string) error { return validateEscapedString(value, []string{"example"}) } testValidValuesForSimpleValidator( @@ -25,6 +26,7 @@ func TestValidateEscapedString(t *testing.T) { } func TestValidateEscapedStringNoVarExpansion(t *testing.T) { + t.Parallel() validator := func(value string) error { return validateEscapedStringNoVarExpansion(value, []string{"example"}) } testValidValuesForSimpleValidator( @@ -45,6 +47,7 @@ func TestValidateEscapedStringNoVarExpansion(t *testing.T) { } func TestValidateValidHeaderName(t *testing.T) { + t.Parallel() validator := func(value string) error { return validateHeaderName(value) } testValidValuesForSimpleValidator( diff --git a/internal/mode/static/nginx/config/validation/framework_test.go b/internal/mode/static/nginx/config/validation/framework_test.go index 6b5c64117a..522e540a8e 100644 --- a/internal/mode/static/nginx/config/validation/framework_test.go +++ b/internal/mode/static/nginx/config/validation/framework_test.go @@ -74,6 +74,7 @@ func testInvalidValuesForSupportedValuesValidator[T configValue]( } func TestValidateInSupportedValues(t *testing.T) { + t.Parallel() supportedValues := map[string]struct{}{ "value1": {}, "value2": {}, @@ -100,6 +101,7 @@ func TestValidateInSupportedValues(t *testing.T) { } func TestValidateNoUnsupportedValues(t *testing.T) { + t.Parallel() unsupportedValues := map[string]struct{}{ "badvalue1": {}, "badvalue2": {}, @@ -128,6 +130,7 @@ func TestValidateNoUnsupportedValues(t *testing.T) { } func TestGetSortedKeysAsString(t *testing.T) { + t.Parallel() values := map[string]struct{}{ "value3": {}, "value1": {}, diff --git a/internal/mode/static/nginx/config/validation/generic_test.go b/internal/mode/static/nginx/config/validation/generic_test.go index 86903bfa38..6934372c0f 100644 --- a/internal/mode/static/nginx/config/validation/generic_test.go +++ b/internal/mode/static/nginx/config/validation/generic_test.go @@ -3,6 +3,7 @@ package validation import "testing" func TestGenericValidator_ValidateEscapedStringNoVarExpansion(t *testing.T) { + t.Parallel() validator := GenericValidator{} testValidValuesForSimpleValidator( @@ -24,6 +25,7 @@ func TestGenericValidator_ValidateEscapedStringNoVarExpansion(t *testing.T) { } func TestValidateServiceName(t *testing.T) { + t.Parallel() validator := GenericValidator{} testValidValuesForSimpleValidator( @@ -45,6 +47,7 @@ func TestValidateServiceName(t *testing.T) { } func TestValidateNginxDuration(t *testing.T) { + t.Parallel() validator := GenericValidator{} testValidValuesForSimpleValidator( @@ -65,6 +68,7 @@ func TestValidateNginxDuration(t *testing.T) { } func TestValidateNginxSize(t *testing.T) { + t.Parallel() validator := GenericValidator{} testValidValuesForSimpleValidator( @@ -86,6 +90,7 @@ func TestValidateNginxSize(t *testing.T) { } func TestValidateEndpoint(t *testing.T) { + t.Parallel() validator := GenericValidator{} testValidValuesForSimpleValidator( diff --git a/internal/mode/static/nginx/config/validation/http_filters_test.go b/internal/mode/static/nginx/config/validation/http_filters_test.go index d58716599c..bd06ed2b41 100644 --- a/internal/mode/static/nginx/config/validation/http_filters_test.go +++ b/internal/mode/static/nginx/config/validation/http_filters_test.go @@ -6,6 +6,7 @@ import ( ) func TestValidateRedirectScheme(t *testing.T) { + t.Parallel() validator := HTTPRedirectValidator{} testValidValuesForSupportedValuesValidator( @@ -24,6 +25,7 @@ func TestValidateRedirectScheme(t *testing.T) { } func TestValidateRedirectPort(t *testing.T) { + t.Parallel() validator := HTTPRedirectValidator{} testValidValuesForSimpleValidator( @@ -35,6 +37,7 @@ func TestValidateRedirectPort(t *testing.T) { } func TestValidateRedirectStatusCode(t *testing.T) { + t.Parallel() validator := HTTPRedirectValidator{} testValidValuesForSupportedValuesValidator( @@ -52,6 +55,7 @@ func TestValidateRedirectStatusCode(t *testing.T) { } func TestValidateHostname(t *testing.T) { + t.Parallel() validator := HTTPRedirectValidator{} testValidValuesForSimpleValidator( @@ -68,6 +72,7 @@ func TestValidateHostname(t *testing.T) { } func TestValidateRewritePath(t *testing.T) { + t.Parallel() validator := HTTPURLRewriteValidator{} testValidValuesForSimpleValidator( @@ -89,6 +94,7 @@ func TestValidateRewritePath(t *testing.T) { } func TestValidateFilterHeaderName(t *testing.T) { + t.Parallel() validator := HTTPHeaderValidator{} testValidValuesForSimpleValidator( @@ -102,6 +108,7 @@ func TestValidateFilterHeaderName(t *testing.T) { } func TestValidateFilterHeaderValue(t *testing.T) { + t.Parallel() validator := HTTPHeaderValidator{} testValidValuesForSimpleValidator( diff --git a/internal/mode/static/nginx/config/validation/http_njs_match_test.go b/internal/mode/static/nginx/config/validation/http_njs_match_test.go index 942d944af8..fd5196c3ed 100644 --- a/internal/mode/static/nginx/config/validation/http_njs_match_test.go +++ b/internal/mode/static/nginx/config/validation/http_njs_match_test.go @@ -5,6 +5,7 @@ import ( ) func TestValidatePathInMatch(t *testing.T) { + t.Parallel() validator := HTTPNJSMatchValidator{} testValidValuesForSimpleValidator( @@ -28,6 +29,7 @@ func TestValidatePathInMatch(t *testing.T) { } func TestValidateHeaderNameInMatch(t *testing.T) { + t.Parallel() validator := HTTPNJSMatchValidator{} testValidValuesForSimpleValidator( @@ -50,6 +52,7 @@ func TestValidateHeaderNameInMatch(t *testing.T) { } func TestValidateHeaderValueInMatch(t *testing.T) { + t.Parallel() validator := HTTPNJSMatchValidator{} testValidValuesForSimpleValidator( @@ -70,6 +73,7 @@ func TestValidateHeaderValueInMatch(t *testing.T) { } func TestValidateQueryParamNameInMatch(t *testing.T) { + t.Parallel() validator := HTTPNJSMatchValidator{} testValidValuesForSimpleValidator( @@ -85,6 +89,7 @@ func TestValidateQueryParamNameInMatch(t *testing.T) { } func TestValidateQueryParamValueInMatch(t *testing.T) { + t.Parallel() validator := HTTPNJSMatchValidator{} testValidValuesForSimpleValidator( @@ -100,6 +105,7 @@ func TestValidateQueryParamValueInMatch(t *testing.T) { } func TestValidateMethodInMatch(t *testing.T) { + t.Parallel() validator := HTTPNJSMatchValidator{} testValidValuesForSupportedValuesValidator( @@ -123,6 +129,7 @@ func TestValidateMethodInMatch(t *testing.T) { } func TestValidateCommonMatchPart(t *testing.T) { + t.Parallel() testValidValuesForSimpleValidator( t, validateCommonNJSMatchPart, diff --git a/internal/mode/static/nginx/config/validation/http_validator.go b/internal/mode/static/nginx/config/validation/http_validator.go index 4e744124c2..9d0ef9ca80 100644 --- a/internal/mode/static/nginx/config/validation/http_validator.go +++ b/internal/mode/static/nginx/config/validation/http_validator.go @@ -6,7 +6,7 @@ import ( // HTTPValidator validates values that will propagate into the NGINX configuration http context. // The validation rules are based on the nginx/config/http types and how they are used in the configuration templates -// of the nginx/config package. Changes to those might require changing the validation rules +// of the nginx/config package. Changes to those might require changing the validation rules. type HTTPValidator struct { HTTPNJSMatchValidator HTTPRedirectValidator diff --git a/internal/mode/static/nginx/config/variable_names_test.go b/internal/mode/static/nginx/config/variable_names_test.go index acaebe9aa2..6a7b6fe6d2 100644 --- a/internal/mode/static/nginx/config/variable_names_test.go +++ b/internal/mode/static/nginx/config/variable_names_test.go @@ -7,6 +7,7 @@ import ( ) func TestConvertStringToSafeVariableName(t *testing.T) { + t.Parallel() tests := []struct { msg string s string @@ -24,7 +25,9 @@ func TestConvertStringToSafeVariableName(t *testing.T) { }, } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(convertStringToSafeVariableName(test.s)).To(Equal(test.expected)) }) @@ -32,6 +35,7 @@ func TestConvertStringToSafeVariableName(t *testing.T) { } func TestGenerateAddHeaderMapVariableName(t *testing.T) { + t.Parallel() tests := []struct { msg string headerName string @@ -49,7 +53,9 @@ func TestGenerateAddHeaderMapVariableName(t *testing.T) { }, } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) actual := generateAddHeaderMapVariableName(test.headerName) g.Expect(actual).To(Equal(test.expected)) diff --git a/internal/mode/static/nginx/config/version_test.go b/internal/mode/static/nginx/config/version_test.go index 4219844c39..176db3dfec 100644 --- a/internal/mode/static/nginx/config/version_test.go +++ b/internal/mode/static/nginx/config/version_test.go @@ -8,6 +8,7 @@ import ( ) func TestExecuteVersion(t *testing.T) { + t.Parallel() g := NewWithT(t) expSubStrings := map[string]int{ "return 200 42;": 1, diff --git a/internal/mode/static/nginx/file/file_suite_test.go b/internal/mode/static/nginx/file/file_suite_test.go index 46afb4ea54..9017ae221f 100644 --- a/internal/mode/static/nginx/file/file_suite_test.go +++ b/internal/mode/static/nginx/file/file_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestFile(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "File Suite") } diff --git a/internal/mode/static/nginx/file/folders_test.go b/internal/mode/static/nginx/file/folders_test.go index 9e1e8f518b..8a4caf5285 100644 --- a/internal/mode/static/nginx/file/folders_test.go +++ b/internal/mode/static/nginx/file/folders_test.go @@ -21,6 +21,7 @@ func writeFile(t *testing.T, name string, data []byte) { } func TestClearFoldersRemoves(t *testing.T) { + t.Parallel() g := NewWithT(t) tempDir := t.TempDir() @@ -41,6 +42,7 @@ func TestClearFoldersRemoves(t *testing.T) { } func TestClearFoldersFails(t *testing.T) { + t.Parallel() files := []string{"file"} testErr := errors.New("test error") @@ -77,7 +79,9 @@ func TestClearFoldersFails(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) removedFiles, err := file.ClearFolders(test.fileMgr, files) diff --git a/internal/mode/static/nginx/file/os_filemanager.go b/internal/mode/static/nginx/file/os_filemanager.go index ffac7caa7a..05547cb046 100644 --- a/internal/mode/static/nginx/file/os_filemanager.go +++ b/internal/mode/static/nginx/file/os_filemanager.go @@ -25,7 +25,7 @@ func (s *StdLibOSFileManager) Remove(name string) error { return os.Remove(name) } -// Write wraps os.File.Write +// Write wraps os.File.Write. func (s *StdLibOSFileManager) Write(file *os.File, contents []byte) error { _, err := file.Write(contents) diff --git a/internal/mode/static/nginx/runtime/manager_test.go b/internal/mode/static/nginx/runtime/manager_test.go index 323bb514a5..1b3be5b446 100644 --- a/internal/mode/static/nginx/runtime/manager_test.go +++ b/internal/mode/static/nginx/runtime/manager_test.go @@ -24,6 +24,7 @@ var _ = Describe("NGINX Runtime Manager", func() { }) func TestFindMainProcess(t *testing.T) { + t.Parallel() readFileFuncGen := func(content []byte) readFileFunc { return func(name string) ([]byte, error) { if name != pidFile { @@ -111,7 +112,9 @@ func TestFindMainProcess(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result, err := findMainProcess(test.ctx, test.checkFile, test.readFile, 2*time.Millisecond) diff --git a/internal/mode/static/nginx/runtime/runtime_suite_test.go b/internal/mode/static/nginx/runtime/runtime_suite_test.go index 7a31e6ebf4..8916c4bf14 100644 --- a/internal/mode/static/nginx/runtime/runtime_suite_test.go +++ b/internal/mode/static/nginx/runtime/runtime_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestRuntime(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Runtime Suite") } diff --git a/internal/mode/static/nginx/runtime/verify_test.go b/internal/mode/static/nginx/runtime/verify_test.go index 0a5431d59c..116ab2e72a 100644 --- a/internal/mode/static/nginx/runtime/verify_test.go +++ b/internal/mode/static/nginx/runtime/verify_test.go @@ -30,6 +30,7 @@ func getTestHTTPClient() *http.Client { } func TestVerifyClient(t *testing.T) { + t.Parallel() c := verifyClient{ client: getTestHTTPClient(), timeout: 25 * time.Millisecond, @@ -86,7 +87,9 @@ func TestVerifyClient(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) err := c.waitForCorrectVersion(test.ctx, test.expectedVersion, "/childfile", []byte("1 2 3"), test.readFile) @@ -101,6 +104,7 @@ func TestVerifyClient(t *testing.T) { } func TestEnsureNewNginxWorkers(t *testing.T) { + t.Parallel() previousContents := []byte("1 2 3") newContents := []byte("4 5 6") @@ -162,7 +166,9 @@ func TestEnsureNewNginxWorkers(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) err := ensureNewNginxWorkers( diff --git a/internal/mode/static/policies/clientsettings/generator_test.go b/internal/mode/static/policies/clientsettings/generator_test.go index 19b3b1de3b..f88616020c 100644 --- a/internal/mode/static/policies/clientsettings/generator_test.go +++ b/internal/mode/static/policies/clientsettings/generator_test.go @@ -13,6 +13,7 @@ import ( ) func TestGenerate(t *testing.T) { + t.Parallel() maxSize := helpers.GetPointer[ngfAPI.Size]("10m") bodyTimeout := helpers.GetPointer[ngfAPI.Duration]("600ms") keepaliveRequests := helpers.GetPointer[int32](900) @@ -150,7 +151,9 @@ func TestGenerate(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) cfgString := string(clientsettings.Generate(test.policy, nil)) @@ -163,6 +166,7 @@ func TestGenerate(t *testing.T) { } func TestGeneratePanics(t *testing.T) { + t.Parallel() g := NewWithT(t) generate := func() { diff --git a/internal/mode/static/policies/clientsettings/validator_test.go b/internal/mode/static/policies/clientsettings/validator_test.go index 8b9a7fcdd4..8f658a80b4 100644 --- a/internal/mode/static/policies/clientsettings/validator_test.go +++ b/internal/mode/static/policies/clientsettings/validator_test.go @@ -53,6 +53,7 @@ func createModifiedPolicy(mod policyModFunc) *ngfAPI.ClientSettingsPolicy { } func TestValidator_Validate(t *testing.T) { + t.Parallel() tests := []struct { name string policy *ngfAPI.ClientSettingsPolicy @@ -132,7 +133,9 @@ func TestValidator_Validate(t *testing.T) { v := clientsettings.NewValidator(validation.GenericValidator{}) for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) conds := v.Validate(test.policy, nil) @@ -142,6 +145,7 @@ func TestValidator_Validate(t *testing.T) { } func TestValidator_ValidatePanics(t *testing.T) { + t.Parallel() v := clientsettings.NewValidator(nil) validate := func() { @@ -154,6 +158,7 @@ func TestValidator_ValidatePanics(t *testing.T) { } func TestValidator_Conflicts(t *testing.T) { + t.Parallel() tests := []struct { polA *ngfAPI.ClientSettingsPolicy polB *ngfAPI.ClientSettingsPolicy @@ -255,7 +260,9 @@ func TestValidator_Conflicts(t *testing.T) { v := clientsettings.NewValidator(nil) for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(v.Conflicts(test.polA, test.polB)).To(Equal(test.conflicts)) @@ -264,6 +271,7 @@ func TestValidator_Conflicts(t *testing.T) { } func TestValidator_ConflictsPanics(t *testing.T) { + t.Parallel() v := clientsettings.NewValidator(nil) conflicts := func() { diff --git a/internal/mode/static/policies/observability/generator_test.go b/internal/mode/static/policies/observability/generator_test.go index 0a5d33d2e5..55805eac51 100644 --- a/internal/mode/static/policies/observability/generator_test.go +++ b/internal/mode/static/policies/observability/generator_test.go @@ -14,6 +14,7 @@ import ( ) func TestGenerate(t *testing.T) { + t.Parallel() ratio := helpers.GetPointer[int32](25) zeroRatio := helpers.GetPointer[int32](0) context := helpers.GetPointer[ngfAPI.TraceContext](ngfAPI.TraceContextExtract) @@ -178,7 +179,9 @@ func TestGenerate(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) cfgString := string(observability.Generate(test.policy, test.globalSettings)) @@ -191,6 +194,7 @@ func TestGenerate(t *testing.T) { } func TestGeneratePanics(t *testing.T) { + t.Parallel() g := NewWithT(t) generate := func() { @@ -201,6 +205,7 @@ func TestGeneratePanics(t *testing.T) { } func TestCreateRatioVarName(t *testing.T) { + t.Parallel() pol := &ngfAPI.ObservabilityPolicy{ Spec: ngfAPI.ObservabilityPolicySpec{ Tracing: &ngfAPI.Tracing{ diff --git a/internal/mode/static/policies/observability/validator_test.go b/internal/mode/static/policies/observability/validator_test.go index 1e726b9fd4..b976542bd2 100644 --- a/internal/mode/static/policies/observability/validator_test.go +++ b/internal/mode/static/policies/observability/validator_test.go @@ -52,6 +52,7 @@ func createModifiedPolicy(mod policyModFunc) *ngfAPI.ObservabilityPolicy { } func TestValidator_Validate(t *testing.T) { + t.Parallel() globalSettings := &policies.GlobalSettings{ NginxProxyValid: true, TelemetryEnabled: true, @@ -184,7 +185,9 @@ func TestValidator_Validate(t *testing.T) { v := observability.NewValidator(validation.GenericValidator{}) for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) conds := v.Validate(test.policy, test.globalSettings) @@ -194,6 +197,7 @@ func TestValidator_Validate(t *testing.T) { } func TestValidator_ValidatePanics(t *testing.T) { + t.Parallel() v := observability.NewValidator(nil) validate := func() { @@ -206,6 +210,7 @@ func TestValidator_ValidatePanics(t *testing.T) { } func TestValidator_Conflicts(t *testing.T) { + t.Parallel() tests := []struct { polA *ngfAPI.ObservabilityPolicy polB *ngfAPI.ObservabilityPolicy @@ -243,7 +248,9 @@ func TestValidator_Conflicts(t *testing.T) { v := observability.NewValidator(nil) for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(v.Conflicts(test.polA, test.polB)).To(Equal(test.conflicts)) @@ -252,6 +259,7 @@ func TestValidator_Conflicts(t *testing.T) { } func TestValidator_ConflictsPanics(t *testing.T) { + t.Parallel() v := observability.NewValidator(nil) conflicts := func() { diff --git a/internal/mode/static/policies/policies_suite_test.go b/internal/mode/static/policies/policies_suite_test.go index 6703df23f1..a22933037a 100644 --- a/internal/mode/static/policies/policies_suite_test.go +++ b/internal/mode/static/policies/policies_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestPolicies(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Policies Suite") } diff --git a/internal/mode/static/sort/sort_test.go b/internal/mode/static/sort/sort_test.go index d1b63e830d..402c8ad6ab 100644 --- a/internal/mode/static/sort/sort_test.go +++ b/internal/mode/static/sort/sort_test.go @@ -11,6 +11,7 @@ import ( ) func TestLessObjectMeta(t *testing.T) { + t.Parallel() before := metav1.Now() later := metav1.NewTime(before.Add(1 * time.Second)) @@ -79,7 +80,9 @@ func TestLessObjectMeta(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := LessObjectMeta(test.meta1, test.meta2) @@ -92,6 +95,7 @@ func TestLessObjectMeta(t *testing.T) { } func TestLessClientObject(t *testing.T) { + t.Parallel() before := metav1.Now() later := metav1.NewTime(before.Add(1 * time.Second)) @@ -176,7 +180,9 @@ func TestLessClientObject(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := LessClientObject(test.obj1, test.obj2) diff --git a/internal/mode/static/state/changed_predicate_test.go b/internal/mode/static/state/changed_predicate_test.go index f82eda158f..5be85dba43 100644 --- a/internal/mode/static/state/changed_predicate_test.go +++ b/internal/mode/static/state/changed_predicate_test.go @@ -11,6 +11,7 @@ import ( ) func TestFuncPredicate(t *testing.T) { + t.Parallel() alwaysTrueFunc := func(_ client.Object, _ types.NamespacedName) bool { return true } emptyObject := &v1.Pod{} @@ -23,6 +24,7 @@ func TestFuncPredicate(t *testing.T) { } func TestFuncPredicate_Panic(t *testing.T) { + t.Parallel() alwaysTrueFunc := func(_ client.Object, _ types.NamespacedName) bool { return true } p := funcPredicate{stateChanged: alwaysTrueFunc} @@ -36,6 +38,7 @@ func TestFuncPredicate_Panic(t *testing.T) { } func TestAnnotationChangedPredicate_Delete(t *testing.T) { + t.Parallel() p := annotationChangedPredicate{} g := NewWithT(t) @@ -43,6 +46,7 @@ func TestAnnotationChangedPredicate_Delete(t *testing.T) { } func TestAnnotationChangedPredicate_Update(t *testing.T) { + t.Parallel() annotation := "test" tests := []struct { @@ -137,7 +141,9 @@ func TestAnnotationChangedPredicate_Update(t *testing.T) { p := annotationChangedPredicate{annotation: annotation} for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) if test.expPanic { upsert := func() { diff --git a/internal/mode/static/state/dataplane/configuration.go b/internal/mode/static/state/dataplane/configuration.go index be2e39fd65..e6b54f252d 100644 --- a/internal/mode/static/state/dataplane/configuration.go +++ b/internal/mode/static/state/dataplane/configuration.go @@ -240,7 +240,7 @@ func buildServers(g *graph.Graph, generator policies.ConfigGenerator) (http, ssl return httpServers, sslServers } -// portPathRules keeps track of hostPathRules per port +// portPathRules keeps track of hostPathRules per port. type portPathRules map[v1.PortNumber]*hostPathRules func (p portPathRules) buildServers() []VirtualServer { diff --git a/internal/mode/static/state/dataplane/configuration_test.go b/internal/mode/static/state/dataplane/configuration_test.go index e053a42d96..77567f7fcc 100644 --- a/internal/mode/static/state/dataplane/configuration_test.go +++ b/internal/mode/static/state/dataplane/configuration_test.go @@ -47,6 +47,7 @@ func createFakePolicy(name string, kind string) policies.Policy { } func TestBuildConfiguration(t *testing.T) { + t.Parallel() const ( invalidMatchesPath = "/not-valid-matches" invalidFiltersPath = "/not-valid-filters" @@ -2298,7 +2299,9 @@ func TestBuildConfiguration(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) fakeGenerator := &policiesfakes.FakeConfigGenerator{ @@ -2340,6 +2343,7 @@ func TestBuildConfiguration(t *testing.T) { } func TestGetPath(t *testing.T) { + t.Parallel() tests := []struct { path *v1.HTTPPathMatch expected string @@ -2368,7 +2372,9 @@ func TestGetPath(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := getPath(test.path) g.Expect(result).To(Equal(test.expected)) @@ -2377,6 +2383,7 @@ func TestGetPath(t *testing.T) { } func TestCreateFilters(t *testing.T) { + t.Parallel() redirect1 := v1.HTTPRouteFilter{ Type: v1.HTTPRouteFilterRequestRedirect, RequestRedirect: &v1.HTTPRequestRedirectFilter{ @@ -2535,7 +2542,9 @@ func TestCreateFilters(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := createHTTPFilters(test.filters) @@ -2545,6 +2554,7 @@ func TestCreateFilters(t *testing.T) { } func TestGetListenerHostname(t *testing.T) { + t.Parallel() var emptyHostname v1.Hostname var hostname v1.Hostname = "example.com" @@ -2571,7 +2581,9 @@ func TestGetListenerHostname(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := getListenerHostname(test.hostname) g.Expect(result).To(Equal(test.expected)) @@ -2594,6 +2606,7 @@ func refsToValidRules(refs ...[]graph.BackendRef) []graph.RouteRule { } func TestBuildUpstreams(t *testing.T) { + t.Parallel() fooEndpoints := []resolver.Endpoint{ { Address: "10.0.0.0", @@ -2815,6 +2828,7 @@ func TestBuildUpstreams(t *testing.T) { } func TestBuildBackendGroups(t *testing.T) { + t.Parallel() createBackendGroup := func(name string, ruleIdx int, backendNames ...string) BackendGroup { backends := make([]Backend, len(backendNames)) for i, name := range backendNames { @@ -2887,6 +2901,7 @@ func TestBuildBackendGroups(t *testing.T) { } func TestHostnameMoreSpecific(t *testing.T) { + t.Parallel() tests := []struct { host1 *v1.Hostname host2 *v1.Hostname @@ -2938,7 +2953,9 @@ func TestHostnameMoreSpecific(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(listenerHostnameMoreSpecific(tc.host1, tc.host2)).To(Equal(tc.host1Wins)) @@ -2947,6 +2964,7 @@ func TestHostnameMoreSpecific(t *testing.T) { } func TestConvertBackendTLS(t *testing.T) { + t.Parallel() btpCaCertRefs := &graph.BackendTLSPolicy{ Source: &v1alpha3.BackendTLSPolicy{ ObjectMeta: metav1.ObjectMeta{ @@ -3014,7 +3032,9 @@ func TestConvertBackendTLS(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(convertBackendTLS(tc.btp)).To(Equal(tc.expected)) @@ -3023,6 +3043,7 @@ func TestConvertBackendTLS(t *testing.T) { } func TestBuildTelemetry(t *testing.T) { + t.Parallel() telemetryConfigured := &graph.NginxProxy{ Source: &ngfAPI.NginxProxy{ Spec: ngfAPI.NginxProxySpec{ @@ -3241,7 +3262,9 @@ func TestBuildTelemetry(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) tel := buildTelemetry(tc.g) sort.Slice(tel.Ratios, func(i, j int) bool { @@ -3253,6 +3276,7 @@ func TestBuildTelemetry(t *testing.T) { } func TestBuildAdditions(t *testing.T) { + t.Parallel() getPolicy := func(kind, name string) policies.Policy { return &policiesfakes.FakePolicy{ GetNameStub: func() string { @@ -3325,7 +3349,9 @@ func TestBuildAdditions(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) generator := &policiesfakes.FakeConfigGenerator{ diff --git a/internal/mode/static/state/dataplane/convert_test.go b/internal/mode/static/state/dataplane/convert_test.go index 1688c1591f..18c978efdb 100644 --- a/internal/mode/static/state/dataplane/convert_test.go +++ b/internal/mode/static/state/dataplane/convert_test.go @@ -10,6 +10,7 @@ import ( ) func TestConvertMatch(t *testing.T) { + t.Parallel() path := v1.HTTPPathMatch{ Type: helpers.GetPointer(v1.PathMatchPathPrefix), Value: helpers.GetPointer("/"), @@ -114,7 +115,9 @@ func TestConvertMatch(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := convertMatch(test.match) @@ -124,6 +127,7 @@ func TestConvertMatch(t *testing.T) { } func TestConvertHTTPRequestRedirectFilter(t *testing.T) { + t.Parallel() tests := []struct { filter *v1.HTTPRequestRedirectFilter expected *HTTPRequestRedirectFilter @@ -152,7 +156,9 @@ func TestConvertHTTPRequestRedirectFilter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := convertHTTPRequestRedirectFilter(test.filter) @@ -162,6 +168,7 @@ func TestConvertHTTPRequestRedirectFilter(t *testing.T) { } func TestConvertHTTPURLRewriteFilter(t *testing.T) { + t.Parallel() tests := []struct { filter *v1.HTTPURLRewriteFilter expected *HTTPURLRewriteFilter @@ -209,7 +216,9 @@ func TestConvertHTTPURLRewriteFilter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := convertHTTPURLRewriteFilter(test.filter) @@ -219,6 +228,7 @@ func TestConvertHTTPURLRewriteFilter(t *testing.T) { } func TestConvertHTTPHeaderFilter(t *testing.T) { + t.Parallel() tests := []struct { filter *v1.HTTPHeaderFilter expected *HTTPHeaderFilter @@ -257,7 +267,9 @@ func TestConvertHTTPHeaderFilter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := convertHTTPHeaderFilter(test.filter) @@ -267,6 +279,7 @@ func TestConvertHTTPHeaderFilter(t *testing.T) { } func TestConvertPathType(t *testing.T) { + t.Parallel() g := NewWithT(t) tests := []struct { diff --git a/internal/mode/static/state/dataplane/sort_test.go b/internal/mode/static/state/dataplane/sort_test.go index 9ab1ca5b4b..e500d05afe 100644 --- a/internal/mode/static/state/dataplane/sort_test.go +++ b/internal/mode/static/state/dataplane/sort_test.go @@ -12,6 +12,7 @@ import ( ) func TestSort(t *testing.T) { + t.Parallel() // timestamps earlier := metav1.Now() later := metav1.NewTime(earlier.Add(1 * time.Second)) diff --git a/internal/mode/static/state/graph/backend_refs_test.go b/internal/mode/static/state/graph/backend_refs_test.go index 140d718864..6c0e47257e 100644 --- a/internal/mode/static/state/graph/backend_refs_test.go +++ b/internal/mode/static/state/graph/backend_refs_test.go @@ -37,6 +37,7 @@ func getModifiedRef(mod func(ref gatewayv1.BackendRef) gatewayv1.BackendRef) gat } func TestValidateRouteBackendRef(t *testing.T) { + t.Parallel() tests := []struct { expectedCondition conditions.Condition name string @@ -84,7 +85,9 @@ func TestValidateRouteBackendRef(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) resolver := newReferenceGrantResolver(nil) @@ -97,6 +100,7 @@ func TestValidateRouteBackendRef(t *testing.T) { } func TestValidateBackendRef(t *testing.T) { + t.Parallel() specificRefGrant := &v1beta1.ReferenceGrant{ Spec: v1beta1.ReferenceGrantSpec{ To: []v1beta1.ReferenceGrantTo{ @@ -226,7 +230,9 @@ func TestValidateBackendRef(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) resolver := newReferenceGrantResolver(test.refGrants) @@ -239,6 +245,7 @@ func TestValidateBackendRef(t *testing.T) { } func TestValidateWeight(t *testing.T) { + t.Parallel() validWeights := []int32{0, 1, 1000000} invalidWeights := []int32{-1, 1000001} @@ -255,6 +262,7 @@ func TestValidateWeight(t *testing.T) { } func TestGetServiceAndPortFromRef(t *testing.T) { + t.Parallel() svc1 := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: "service1", @@ -323,7 +331,9 @@ func TestGetServiceAndPortFromRef(t *testing.T) { refPath := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) svcNsName, servicePort, err := getServiceAndPortFromRef(test.ref, "test", services, refPath) @@ -336,6 +346,7 @@ func TestGetServiceAndPortFromRef(t *testing.T) { } func TestAddBackendRefsToRulesTest(t *testing.T) { + t.Parallel() sectionNameRefs := []ParentRef{ { Idx: 0, @@ -677,7 +688,9 @@ func TestAddBackendRefsToRulesTest(t *testing.T) { } for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) resolver := newReferenceGrantResolver(nil) addBackendRefsToRules(test.route, resolver, services, test.policies) @@ -694,6 +707,7 @@ func TestAddBackendRefsToRulesTest(t *testing.T) { } func TestCreateBackend(t *testing.T) { + t.Parallel() createService := func(name string) *v1.Service { return &v1.Service{ ObjectMeta: metav1.ObjectMeta{ @@ -924,7 +938,9 @@ func TestCreateBackend(t *testing.T) { refPath := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) resolver := newReferenceGrantResolver(nil) @@ -952,6 +968,7 @@ func TestCreateBackend(t *testing.T) { } func TestGetServicePort(t *testing.T) { + t.Parallel() svc := &v1.Service{ Spec: v1.ServiceSpec{ Ports: []v1.ServicePort{ @@ -982,6 +999,7 @@ func TestGetServicePort(t *testing.T) { } func TestValidateBackendTLSPolicyMatchingAllBackends(t *testing.T) { + t.Parallel() getBtp := func(name, caCertName string) *BackendTLSPolicy { return &BackendTLSPolicy{ Source: &v1alpha3.BackendTLSPolicy{ @@ -1072,7 +1090,9 @@ func TestValidateBackendTLSPolicyMatchingAllBackends(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) cond := validateBackendTLSPolicyMatchingAllBackends(test.backendRefs) @@ -1083,6 +1103,7 @@ func TestValidateBackendTLSPolicyMatchingAllBackends(t *testing.T) { } func TestFindBackendTLSPolicyForService(t *testing.T) { + t.Parallel() oldCreationTimestamp := metav1.Now() newCreationTimestamp := metav1.Now() getBtp := func(name string, timestamp metav1.Time) *BackendTLSPolicy { @@ -1147,7 +1168,9 @@ func TestFindBackendTLSPolicyForService(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) btp, err := findBackendTLSPolicyForService(test.backendTLSPolicies, ref.Namespace, string(ref.Name), "test") diff --git a/internal/mode/static/state/graph/backend_tls_policy_test.go b/internal/mode/static/state/graph/backend_tls_policy_test.go index b4ded8f21d..3f09afa92b 100644 --- a/internal/mode/static/state/graph/backend_tls_policy_test.go +++ b/internal/mode/static/state/graph/backend_tls_policy_test.go @@ -16,6 +16,7 @@ import ( ) func TestProcessBackendTLSPoliciesEmpty(t *testing.T) { + t.Parallel() backendTLSPolicies := map[types.NamespacedName]*v1alpha3.BackendTLSPolicy{ {Namespace: "test", Name: "tls-policy"}: { ObjectMeta: metav1.ObjectMeta{ @@ -70,7 +71,9 @@ func TestProcessBackendTLSPoliciesEmpty(t *testing.T) { } for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) processed := processBackendTLSPolicies(test.backendTLSPolicies, nil, "test", test.gateway) @@ -81,6 +84,7 @@ func TestProcessBackendTLSPoliciesEmpty(t *testing.T) { } func TestValidateBackendTLSPolicy(t *testing.T) { + t.Parallel() targetRefNormalCase := []v1alpha2.LocalPolicyTargetReferenceWithSectionName{ { LocalPolicyTargetReference: v1alpha2.LocalPolicyTargetReference{ @@ -394,7 +398,9 @@ func TestValidateBackendTLSPolicy(t *testing.T) { configMapResolver := newConfigMapResolver(configMaps) for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) valid, ignored, conds := validateBackendTLSPolicy(test.tlsPolicy, configMapResolver, "test") diff --git a/internal/mode/static/state/graph/configmaps_test.go b/internal/mode/static/state/graph/configmaps_test.go index 4e9430c510..82ad974244 100644 --- a/internal/mode/static/state/graph/configmaps_test.go +++ b/internal/mode/static/state/graph/configmaps_test.go @@ -88,6 +88,7 @@ UdxohGqleWFMQ3UNLOvc9Fk+q72ryg== ) func TestValidateCA(t *testing.T) { + t.Parallel() base64Data := make([]byte, base64.StdEncoding.EncodedLen(len(caBlock))) base64.StdEncoding.Encode(base64Data, []byte(caBlock)) @@ -119,7 +120,9 @@ func TestValidateCA(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) err := validateCA(test.data) @@ -133,6 +136,7 @@ func TestValidateCA(t *testing.T) { } func TestResolve(t *testing.T) { + t.Parallel() configMaps := map[types.NamespacedName]*v1.ConfigMap{ {Namespace: "test", Name: "configmap1"}: { ObjectMeta: metav1.ObjectMeta{ @@ -207,7 +211,9 @@ func TestResolve(t *testing.T) { } for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) err := configMapResolver.resolve(test.nsname) diff --git a/internal/mode/static/state/graph/gateway.go b/internal/mode/static/state/graph/gateway.go index 6a826f80fc..2b73b46be2 100644 --- a/internal/mode/static/state/graph/gateway.go +++ b/internal/mode/static/state/graph/gateway.go @@ -33,7 +33,7 @@ type processedGateways struct { Ignored map[types.NamespacedName]*v1.Gateway } -// GetAllNsNames returns all the NamespacedNames of the Gateway resources that belong to NGF +// GetAllNsNames returns all the NamespacedNames of the Gateway resources that belong to NGF. func (gws processedGateways) GetAllNsNames() []types.NamespacedName { winnerCnt := 0 if gws.Winner != nil { diff --git a/internal/mode/static/state/graph/gateway_listener_test.go b/internal/mode/static/state/graph/gateway_listener_test.go index 96aba1a66c..4255067b77 100644 --- a/internal/mode/static/state/graph/gateway_listener_test.go +++ b/internal/mode/static/state/graph/gateway_listener_test.go @@ -15,6 +15,7 @@ import ( ) func TestValidateHTTPListener(t *testing.T) { + t.Parallel() protectedPorts := ProtectedPorts{9113: "MetricsPort"} tests := []struct { @@ -59,7 +60,9 @@ func TestValidateHTTPListener(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) v := createHTTPListenerValidator(protectedPorts) @@ -73,6 +76,7 @@ func TestValidateHTTPListener(t *testing.T) { } func TestValidateHTTPSListener(t *testing.T) { + t.Parallel() secretNs := "secret-ns" validSecretRef := v1.SecretObjectReference{ @@ -226,7 +230,9 @@ func TestValidateHTTPSListener(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) v := createHTTPSListenerValidator(protectedPorts) @@ -239,6 +245,7 @@ func TestValidateHTTPSListener(t *testing.T) { } func TestValidateListenerHostname(t *testing.T) { + t.Parallel() tests := []struct { hostname *v1.Hostname name string @@ -272,7 +279,9 @@ func TestValidateListenerHostname(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) conds, attachable := validateListenerHostname(v1.Listener{Hostname: test.hostname}) @@ -289,6 +298,7 @@ func TestValidateListenerHostname(t *testing.T) { } func TestGetAndValidateListenerSupportedKinds(t *testing.T) { + t.Parallel() HTTPRouteGroupKind := []v1.RouteGroupKind{ { Kind: kinds.HTTPRoute, @@ -377,7 +387,9 @@ func TestGetAndValidateListenerSupportedKinds(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) listener := v1.Listener{ @@ -402,6 +414,7 @@ func TestGetAndValidateListenerSupportedKinds(t *testing.T) { } func TestValidateListenerLabelSelector(t *testing.T) { + t.Parallel() tests := []struct { selector *metav1.LabelSelector from v1.FromNamespaces @@ -429,7 +442,9 @@ func TestValidateListenerLabelSelector(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) // create iteration variable inside the loop to fix implicit memory aliasing @@ -457,19 +472,24 @@ func TestValidateListenerLabelSelector(t *testing.T) { } func TestValidateListenerPort(t *testing.T) { + t.Parallel() validPorts := []v1.PortNumber{1, 80, 443, 1000, 50000, 65535} invalidPorts := []v1.PortNumber{-1, 0, 65536, 80000, 9113} protectedPorts := ProtectedPorts{9113: "MetricsPort"} for _, p := range validPorts { + p := p t.Run(fmt.Sprintf("valid port %d", p), func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(validateListenerPort(p, protectedPorts)).To(Succeed()) }) } for _, p := range invalidPorts { + p := p t.Run(fmt.Sprintf("invalid port %d", p), func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(validateListenerPort(p, protectedPorts)).ToNot(Succeed()) }) diff --git a/internal/mode/static/state/graph/gateway_test.go b/internal/mode/static/state/graph/gateway_test.go index 8bb89471c4..00a55a6803 100644 --- a/internal/mode/static/state/graph/gateway_test.go +++ b/internal/mode/static/state/graph/gateway_test.go @@ -19,6 +19,7 @@ import ( ) func TestProcessedGatewaysGetAllNsNames(t *testing.T) { + t.Parallel() winner := &v1.Gateway{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", @@ -58,7 +59,9 @@ func TestProcessedGatewaysGetAllNsNames(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := test.gws.GetAllNsNames() g.Expect(result).To(Equal(test.expected)) @@ -67,6 +70,7 @@ func TestProcessedGatewaysGetAllNsNames(t *testing.T) { } func TestProcessGateways(t *testing.T) { + t.Parallel() const gcName = "test-gc" winner := &v1.Gateway{ @@ -133,7 +137,9 @@ func TestProcessGateways(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := processGateways(test.gws, gcName) g.Expect(helpers.Diff(test.expected, result)).To(BeEmpty()) @@ -142,6 +148,7 @@ func TestProcessGateways(t *testing.T) { } func TestBuildGateway(t *testing.T) { + t.Parallel() const gcName = "my-gateway-class" labelSet := map[string]string{ @@ -930,7 +937,9 @@ func TestBuildGateway(t *testing.T) { }) for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) resolver := newReferenceGrantResolver(test.refGrants) result := buildGateway(test.gateway, secretResolver, test.gatewayClass, resolver, protectedPorts) diff --git a/internal/mode/static/state/graph/gatewayclass_test.go b/internal/mode/static/state/graph/gatewayclass_test.go index 1b10997e4d..243f74de30 100644 --- a/internal/mode/static/state/graph/gatewayclass_test.go +++ b/internal/mode/static/state/graph/gatewayclass_test.go @@ -19,6 +19,7 @@ import ( ) func TestProcessGatewayClasses(t *testing.T) { + t.Parallel() gcName := "test-gc" ctlrName := "test-ctlr" winner := &v1.GatewayClass{ @@ -113,7 +114,9 @@ func TestProcessGatewayClasses(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result, exists := processGatewayClasses(test.gcs, gcName, ctlrName) g.Expect(helpers.Diff(test.expected, result)).To(BeEmpty()) @@ -123,6 +126,7 @@ func TestProcessGatewayClasses(t *testing.T) { } func TestBuildGatewayClass(t *testing.T) { + t.Parallel() validGC := &v1.GatewayClass{} gcWithParams := &v1.GatewayClass{ @@ -287,7 +291,9 @@ func TestBuildGatewayClass(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := buildGatewayClass(test.gc, test.np, test.crdMetadata) diff --git a/internal/mode/static/state/graph/graph_test.go b/internal/mode/static/state/graph/graph_test.go index 7c3bc3ea06..cd95945052 100644 --- a/internal/mode/static/state/graph/graph_test.go +++ b/internal/mode/static/state/graph/graph_test.go @@ -30,6 +30,7 @@ import ( ) func TestBuildGraph(t *testing.T) { + t.Parallel() const ( gcName = "my-class" controllerName = "my.controller" @@ -656,7 +657,9 @@ func TestBuildGraph(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) fakePolicyValidator := &validationfakes.FakePolicyValidator{} @@ -679,6 +682,7 @@ func TestBuildGraph(t *testing.T) { } func TestIsReferenced(t *testing.T) { + t.Parallel() baseSecret := &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ Namespace: testNs, @@ -971,7 +975,9 @@ func TestIsReferenced(t *testing.T) { }, } for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) test.graph.GatewayClass = test.gc @@ -982,6 +988,7 @@ func TestIsReferenced(t *testing.T) { } func TestIsNGFPolicyRelevant(t *testing.T) { + t.Parallel() policyGVK := schema.GroupVersionKind{Kind: "MyKind"} existingPolicyNsName := types.NamespacedName{Namespace: "test", Name: "pol"} @@ -1123,7 +1130,9 @@ func TestIsNGFPolicyRelevant(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) relevant := test.graph.IsNGFPolicyRelevant(test.policy, policyGVK, test.nsname) @@ -1133,6 +1142,7 @@ func TestIsNGFPolicyRelevant(t *testing.T) { } func TestIsNGFPolicyRelevantPanics(t *testing.T) { + t.Parallel() g := NewWithT(t) graph := &Graph{} nsname := types.NamespacedName{Namespace: "test", Name: "pol"} diff --git a/internal/mode/static/state/graph/grpcroute.go b/internal/mode/static/state/graph/grpcroute.go index cbbbaf65b3..ea3f576972 100644 --- a/internal/mode/static/state/graph/grpcroute.go +++ b/internal/mode/static/state/graph/grpcroute.go @@ -274,7 +274,7 @@ func validateGRPCFilter( } // convertGRPCFilters converts GRPCRouteFilters (a subset of HTTPRouteFilter) to HTTPRouteFilters -// so we can reuse the logic from HTTPRoute filter validation and processing +// so we can reuse the logic from HTTPRoute filter validation and processing. func convertGRPCFilters(filters []v1.GRPCRouteFilter) []v1.HTTPRouteFilter { if len(filters) == 0 { return nil diff --git a/internal/mode/static/state/graph/grpcroute_test.go b/internal/mode/static/state/graph/grpcroute_test.go index ed8e455853..09d7d79638 100644 --- a/internal/mode/static/state/graph/grpcroute_test.go +++ b/internal/mode/static/state/graph/grpcroute_test.go @@ -79,6 +79,7 @@ func createGRPCRoute( } func TestBuildGRPCRoutes(t *testing.T) { + t.Parallel() gwNsName := types.NamespacedName{Namespace: "test", Name: "gateway"} gr := createGRPCRoute("gr-1", gwNsName.Name, "example.com", []v1.GRPCRouteRule{}) @@ -136,7 +137,9 @@ func TestBuildGRPCRoutes(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) routes := buildRoutesForGateways( validator, @@ -151,6 +154,7 @@ func TestBuildGRPCRoutes(t *testing.T) { } func TestBuildGRPCRoute(t *testing.T) { + t.Parallel() gatewayNsName := types.NamespacedName{Namespace: "test", Name: "gateway"} methodMatchRule := createGRPCMethodMatch("myService", "myMethod", "Exact") @@ -684,7 +688,9 @@ func TestBuildGRPCRoute(t *testing.T) { gatewayNsNames := []types.NamespacedName{gatewayNsName} for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) route := buildGRPCRoute(test.validator, test.gr, gatewayNsNames, test.http2disabled) @@ -694,6 +700,7 @@ func TestBuildGRPCRoute(t *testing.T) { } func TestConvertGRPCMatches(t *testing.T) { + t.Parallel() methodMatch := createGRPCMethodMatch("myService", "myMethod", "Exact").Matches headersMatch := createGRPCHeadersMatch("Exact", "MyHeader", "SomeValue").Matches @@ -755,7 +762,9 @@ func TestConvertGRPCMatches(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) httpMatches := convertGRPCMatches(test.methodMatches) @@ -765,6 +774,7 @@ func TestConvertGRPCMatches(t *testing.T) { } func TestConvertGRPCFilters(t *testing.T) { + t.Parallel() grFilters := []v1.GRPCRouteFilter{ { Type: "RequestHeaderModifier", diff --git a/internal/mode/static/state/graph/httproute_test.go b/internal/mode/static/state/graph/httproute_test.go index 4686908a26..09d4bbd48e 100644 --- a/internal/mode/static/state/graph/httproute_test.go +++ b/internal/mode/static/state/graph/httproute_test.go @@ -87,6 +87,7 @@ func addFilterToPath(hr *gatewayv1.HTTPRoute, path string, filter gatewayv1.HTTP } func TestBuildHTTPRoutes(t *testing.T) { + t.Parallel() gwNsName := types.NamespacedName{Namespace: "test", Name: "gateway"} hr := createHTTPRoute("hr-1", gwNsName.Name, "example.com", "/") @@ -143,7 +144,9 @@ func TestBuildHTTPRoutes(t *testing.T) { validator := &validationfakes.FakeHTTPFieldsValidator{} for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) routes := buildRoutesForGateways( validator, @@ -158,6 +161,7 @@ func TestBuildHTTPRoutes(t *testing.T) { } func TestBuildHTTPRoute(t *testing.T) { + t.Parallel() const ( invalidPath = "/invalid" invalidRedirectHostname = "invalid.example.com" @@ -579,7 +583,9 @@ func TestBuildHTTPRoute(t *testing.T) { gatewayNsNames := []types.NamespacedName{gatewayNsName} for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) route := buildHTTPRoute(test.validator, test.hr, gatewayNsNames) @@ -589,6 +595,7 @@ func TestBuildHTTPRoute(t *testing.T) { } func TestValidateMatch(t *testing.T) { + t.Parallel() createAllValidValidator := func() *validationfakes.FakeHTTPFieldsValidator { v := &validationfakes.FakeHTTPFieldsValidator{} v.ValidateMethodInMatchReturns(true, nil) @@ -832,7 +839,9 @@ func TestValidateMatch(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) allErrs := validateMatch(test.validator, test.match, field.NewPath("test")) g.Expect(allErrs).To(HaveLen(test.expectErrCount)) @@ -841,6 +850,7 @@ func TestValidateMatch(t *testing.T) { } func TestValidateFilter(t *testing.T) { + t.Parallel() tests := []struct { filter gatewayv1.HTTPRouteFilter name string @@ -890,7 +900,9 @@ func TestValidateFilter(t *testing.T) { filterPath := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) allErrs := validateFilter(&validationfakes.FakeHTTPFieldsValidator{}, test.filter, filterPath) g.Expect(allErrs).To(HaveLen(test.expectErrCount)) @@ -899,6 +911,7 @@ func TestValidateFilter(t *testing.T) { } func TestValidateFilterRedirect(t *testing.T) { + t.Parallel() createAllValidValidator := func() *validationfakes.FakeHTTPFieldsValidator { v := &validationfakes.FakeHTTPFieldsValidator{} @@ -1018,7 +1031,9 @@ func TestValidateFilterRedirect(t *testing.T) { filterPath := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) allErrs := validateFilterRedirect(test.validator, test.requestRedirect, filterPath) @@ -1028,6 +1043,7 @@ func TestValidateFilterRedirect(t *testing.T) { } func TestValidateFilterRewrite(t *testing.T) { + t.Parallel() tests := []struct { urlRewrite *gatewayv1.HTTPURLRewriteFilter validator *validationfakes.FakeHTTPFieldsValidator @@ -1136,7 +1152,9 @@ func TestValidateFilterRewrite(t *testing.T) { filterPath := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) allErrs := validateFilterRewrite(test.validator, test.urlRewrite, filterPath) g.Expect(allErrs).To(HaveLen(test.expectErrCount)) diff --git a/internal/mode/static/state/graph/namespace_test.go b/internal/mode/static/state/graph/namespace_test.go index 8781fc6f8c..1e97f62b7a 100644 --- a/internal/mode/static/state/graph/namespace_test.go +++ b/internal/mode/static/state/graph/namespace_test.go @@ -12,6 +12,7 @@ import ( ) func TestBuildReferencedNamespaces(t *testing.T) { + t.Parallel() ns1 := &v1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: "ns1", @@ -169,7 +170,9 @@ func TestBuildReferencedNamespaces(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(buildReferencedNamespaces(clusterNamespaces, test.gw)).To(Equal(test.expectedRefNS)) }) @@ -177,6 +180,7 @@ func TestBuildReferencedNamespaces(t *testing.T) { } func TestIsNamespaceReferenced(t *testing.T) { + t.Parallel() tests := []struct { ns *v1.Namespace gw *Gateway @@ -212,7 +216,9 @@ func TestIsNamespaceReferenced(t *testing.T) { // Other test cases should be covered by testing of BuildReferencedNamespaces for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(isNamespaceReferenced(test.ns, test.gw)).To(Equal(test.exp)) }) diff --git a/internal/mode/static/state/graph/nginxproxy_test.go b/internal/mode/static/state/graph/nginxproxy_test.go index 1aed0913fc..850eaf62c3 100644 --- a/internal/mode/static/state/graph/nginxproxy_test.go +++ b/internal/mode/static/state/graph/nginxproxy_test.go @@ -16,6 +16,7 @@ import ( ) func TestGetNginxProxy(t *testing.T) { + t.Parallel() tests := []struct { nps map[types.NamespacedName]*ngfAPI.NginxProxy gc *v1.GatewayClass @@ -79,7 +80,9 @@ func TestGetNginxProxy(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(buildNginxProxy(test.nps, test.gc, &validationfakes.FakeGenericValidator{})).To(Equal(test.expNP)) @@ -88,6 +91,7 @@ func TestGetNginxProxy(t *testing.T) { } func TestIsNginxProxyReferenced(t *testing.T) { + t.Parallel() tests := []struct { gc *GatewayClass npName types.NamespacedName @@ -143,7 +147,9 @@ func TestIsNginxProxyReferenced(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(isNginxProxyReferenced(test.npName, test.gc)).To(Equal(test.expRes)) @@ -152,6 +158,7 @@ func TestIsNginxProxyReferenced(t *testing.T) { } func TestGCReferencesAnyNginxProxy(t *testing.T) { + t.Parallel() tests := []struct { gc *v1.GatewayClass name string @@ -211,7 +218,9 @@ func TestGCReferencesAnyNginxProxy(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(gcReferencesAnyNginxProxy(test.gc)).To(Equal(test.expRes)) @@ -220,6 +229,7 @@ func TestGCReferencesAnyNginxProxy(t *testing.T) { } func TestValidateNginxProxy(t *testing.T) { + t.Parallel() createValidValidator := func() *validationfakes.FakeGenericValidator { v := &validationfakes.FakeGenericValidator{} v.ValidateEscapedStringNoVarExpansionReturns(nil) @@ -329,7 +339,9 @@ func TestValidateNginxProxy(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) allErrs := validateNginxProxy(test.validator, test.np) diff --git a/internal/mode/static/state/graph/policies_test.go b/internal/mode/static/state/graph/policies_test.go index b41d663532..5e52915bba 100644 --- a/internal/mode/static/state/graph/policies_test.go +++ b/internal/mode/static/state/graph/policies_test.go @@ -23,6 +23,7 @@ import ( var testNs = "test" func TestAttachPolicies(t *testing.T) { + t.Parallel() policyGVK := schema.GroupVersionKind{Group: "Group", Version: "Version", Kind: "Policy"} gwPolicyKey := createTestPolicyKey(policyGVK, "gw-policy") @@ -219,7 +220,9 @@ func TestAttachPolicies(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) test.graph.attachPolicies("nginx-gateway") @@ -229,6 +232,7 @@ func TestAttachPolicies(t *testing.T) { } func TestAttachPolicyToRoute(t *testing.T) { + t.Parallel() routeNsName := types.NamespacedName{Namespace: testNs, Name: "hr-route"} createRoute := func(routeType RouteType, valid, attachable, parentRefs bool) *L7Route { @@ -360,7 +364,9 @@ func TestAttachPolicyToRoute(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) attachPolicyToRoute(test.policy, test.route, "nginx-gateway") @@ -377,6 +383,7 @@ func TestAttachPolicyToRoute(t *testing.T) { } func TestAttachPolicyToGateway(t *testing.T) { + t.Parallel() gatewayNsName := types.NamespacedName{Namespace: testNs, Name: "gateway"} gateway2NsName := types.NamespacedName{Namespace: testNs, Name: "gateway2"} ignoredGatewayNsName := types.NamespacedName{Namespace: testNs, Name: "ignored"} @@ -524,7 +531,9 @@ func TestAttachPolicyToGateway(t *testing.T) { ignoredGatewayNsName: nil, } + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) attachPolicyToGateway(test.policy, test.policy.TargetRefs[0], test.gw, ignoredGateways, "nginx-gateway") @@ -541,6 +550,7 @@ func TestAttachPolicyToGateway(t *testing.T) { } func TestProcessPolicies(t *testing.T) { + t.Parallel() policyGVK := schema.GroupVersionKind{Group: "Group", Version: "Version", Kind: "MyPolicy"} // These refs reference objects that belong to NGF. @@ -758,7 +768,9 @@ func TestProcessPolicies(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) processed := processPolicies(test.policies, test.validator, gateways, routes, nil) @@ -768,6 +780,7 @@ func TestProcessPolicies(t *testing.T) { } func TestMarkConflictedPolicies(t *testing.T) { + t.Parallel() hrRef := createTestRef(kinds.HTTPRoute, v1.GroupName, "hr") hrTargetRef := PolicyTargetRef{ Kind: hrRef.Kind, @@ -895,7 +908,9 @@ func TestMarkConflictedPolicies(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) markConflictedPolicies(test.policies, test.fakeValidator) diff --git a/internal/mode/static/state/graph/policy_ancestor_test.go b/internal/mode/static/state/graph/policy_ancestor_test.go index 7b90a3b3a6..19b3904bb0 100644 --- a/internal/mode/static/state/graph/policy_ancestor_test.go +++ b/internal/mode/static/state/graph/policy_ancestor_test.go @@ -11,6 +11,7 @@ import ( ) func TestBackendTLSPolicyAncestorsFull(t *testing.T) { + t.Parallel() createCurStatus := func(numAncestors int, ctlrName string) []v1alpha2.PolicyAncestorStatus { statuses := make([]v1alpha2.PolicyAncestorStatus, 0, numAncestors) @@ -46,7 +47,9 @@ func TestBackendTLSPolicyAncestorsFull(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) full := backendTLSPolicyAncestorsFull(test.curStatus, "nginx-gateway") @@ -56,6 +59,7 @@ func TestBackendTLSPolicyAncestorsFull(t *testing.T) { } func TestNGFPolicyAncestorsFull(t *testing.T) { + t.Parallel() type ancestorConfig struct { numCurrNGFAncestors int numCurrNonNGFAncestors int @@ -156,7 +160,9 @@ func TestNGFPolicyAncestorsFull(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) policy := createPolicy(test.cfg) diff --git a/internal/mode/static/state/graph/reference_grant_test.go b/internal/mode/static/state/graph/reference_grant_test.go index 3b61e6f1c5..cba9555ca0 100644 --- a/internal/mode/static/state/graph/reference_grant_test.go +++ b/internal/mode/static/state/graph/reference_grant_test.go @@ -12,6 +12,7 @@ import ( ) func TestReferenceGrantResolver(t *testing.T) { + t.Parallel() gwNs := "gw-ns" secretNsName := types.NamespacedName{Namespace: "test", Name: "certificate"} @@ -160,7 +161,9 @@ func TestReferenceGrantResolver(t *testing.T) { resolver := newReferenceGrantResolver(refGrants) for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(resolver.refAllowed(test.to, test.from)).To(Equal(test.allowed)) @@ -169,6 +172,7 @@ func TestReferenceGrantResolver(t *testing.T) { } func TestToSecret(t *testing.T) { + t.Parallel() ref := toSecret(types.NamespacedName{Namespace: "ns", Name: "secret"}) exp := toResource{ @@ -182,6 +186,7 @@ func TestToSecret(t *testing.T) { } func TestToService(t *testing.T) { + t.Parallel() ref := toService(types.NamespacedName{Namespace: "ns", Name: "service"}) exp := toResource{ @@ -195,6 +200,7 @@ func TestToService(t *testing.T) { } func TestFromGateway(t *testing.T) { + t.Parallel() ref := fromGateway("ns") exp := fromResource{ @@ -208,6 +214,7 @@ func TestFromGateway(t *testing.T) { } func TestFromHTTPRoute(t *testing.T) { + t.Parallel() ref := fromHTTPRoute("ns") exp := fromResource{ diff --git a/internal/mode/static/state/graph/route_common.go b/internal/mode/static/state/graph/route_common.go index 25001cc323..336e722dbe 100644 --- a/internal/mode/static/state/graph/route_common.go +++ b/internal/mode/static/state/graph/route_common.go @@ -49,13 +49,13 @@ type ParentRefAttachmentStatus struct { type RouteType string const ( - // RouteTypeHTTP indicates that the RouteType of the L7Route is HTTP + // RouteTypeHTTP indicates that the RouteType of the L7Route is HTTP. RouteTypeHTTP RouteType = "http" - // RouteTypeGRPC indicates that the RouteType of the L7Route is gRPC + // RouteTypeGRPC indicates that the RouteType of the L7Route is gRPC. RouteTypeGRPC RouteType = "grpc" ) -// RouteKey is the unique identifier for a L7Route +// RouteKey is the unique identifier for a L7Route. type RouteKey struct { // NamespacedName is the NamespacedName of the Route. NamespacedName types.NamespacedName @@ -63,7 +63,7 @@ type RouteKey struct { RouteType RouteType } -// L7Route is the generic type for the layer 7 routes, HTTPRoute and GRPCRoute +// L7Route is the generic type for the layer 7 routes, HTTPRoute and GRPCRoute. type L7Route struct { // Source is the source Gateway API object of the Route. Source client.Object @@ -111,7 +111,7 @@ type RouteBackendRef struct { Filters []any } -// CreateRouteKey takes a client.Object and creates a RouteKey +// CreateRouteKey takes a client.Object and creates a RouteKey. func CreateRouteKey(obj client.Object) RouteKey { nsName := types.NamespacedName{ Name: obj.GetName(), @@ -467,7 +467,7 @@ func match(listenerHost, routeHost string) bool { // // This function assumes that the two hostnames match each other, either: // - Exactly -// - One as a substring of the other +// - One as a substring of the other. func GetMoreSpecificHostname(hostname1, hostname2 string) string { if hostname1 == hostname2 { return hostname1 diff --git a/internal/mode/static/state/graph/route_common_test.go b/internal/mode/static/state/graph/route_common_test.go index 3eb96f6f69..fe4be14eee 100644 --- a/internal/mode/static/state/graph/route_common_test.go +++ b/internal/mode/static/state/graph/route_common_test.go @@ -21,6 +21,7 @@ import ( ) func TestBuildSectionNameRefs(t *testing.T) { + t.Parallel() const routeNamespace = "test" gwNsName1 := types.NamespacedName{Namespace: routeNamespace, Name: "gateway-1"} @@ -121,7 +122,9 @@ func TestBuildSectionNameRefs(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result, err := buildSectionNameRefs(test.parentRefs, routeNamespace, gwNsNames) @@ -136,6 +139,7 @@ func TestBuildSectionNameRefs(t *testing.T) { } func TestFindGatewayForParentRef(t *testing.T) { + t.Parallel() gwNsName1 := types.NamespacedName{Namespace: "test-1", Name: "gateway-1"} gwNsName2 := types.NamespacedName{Namespace: "test-2", Name: "gateway-2"} @@ -210,7 +214,9 @@ func TestFindGatewayForParentRef(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) gw, found := findGatewayForParentRef(test.ref, routeNamespace, gwNsNames) @@ -221,6 +227,7 @@ func TestFindGatewayForParentRef(t *testing.T) { } func TestBindRouteToListeners(t *testing.T) { + t.Parallel() // we create a new listener each time because the function under test can modify it createListener := func(name string) *Listener { return &Listener{ @@ -1067,7 +1074,9 @@ func TestBindRouteToListeners(t *testing.T) { }, } for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) bindRouteToListeners( @@ -1084,6 +1093,7 @@ func TestBindRouteToListeners(t *testing.T) { } func TestFindAcceptedHostnames(t *testing.T) { + t.Parallel() var listenerHostnameFoo gatewayv1.Hostname = "foo.example.com" var listenerHostnameCafe gatewayv1.Hostname = "cafe.example.com" var listenerHostnameWildcard gatewayv1.Hostname = "*.example.com" @@ -1158,7 +1168,9 @@ func TestFindAcceptedHostnames(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := findAcceptedHostnames(test.listenerHostname, test.routeHostnames) g.Expect(result).To(Equal(test.expected)) @@ -1167,6 +1179,7 @@ func TestFindAcceptedHostnames(t *testing.T) { } func TestGetHostname(t *testing.T) { + t.Parallel() var emptyHostname gatewayv1.Hostname var hostname gatewayv1.Hostname = "example.com" @@ -1193,7 +1206,9 @@ func TestGetHostname(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.msg, func(t *testing.T) { + t.Parallel() g := NewWithT(t) result := getHostname(test.h) g.Expect(result).To(Equal(test.expected)) @@ -1202,6 +1217,7 @@ func TestGetHostname(t *testing.T) { } func TestValidateHostnames(t *testing.T) { + t.Parallel() const validHostname = "example.com" tests := []struct { @@ -1231,7 +1247,9 @@ func TestValidateHostnames(t *testing.T) { path := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) err := validateHostnames(test.hostnames, path) @@ -1246,6 +1264,7 @@ func TestValidateHostnames(t *testing.T) { } func TestValidateFilterRequestHeaderModifier(t *testing.T) { + t.Parallel() createAllValidValidator := func() *validationfakes.FakeHTTPFieldsValidator { v := &validationfakes.FakeHTTPFieldsValidator{} return v @@ -1379,7 +1398,9 @@ func TestValidateFilterRequestHeaderModifier(t *testing.T) { filterPath := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) allErrs := validateFilterHeaderModifier( test.validator, test.filter.RequestHeaderModifier, filterPath, @@ -1390,6 +1411,7 @@ func TestValidateFilterRequestHeaderModifier(t *testing.T) { } func TestValidateFilterResponseHeaderModifier(t *testing.T) { + t.Parallel() createAllValidValidator := func() *validationfakes.FakeHTTPFieldsValidator { v := &validationfakes.FakeHTTPFieldsValidator{} return v @@ -1557,7 +1579,9 @@ func TestValidateFilterResponseHeaderModifier(t *testing.T) { filterPath := field.NewPath("test") for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) allErrs := validateFilterResponseHeaderModifier( test.validator, test.filter.ResponseHeaderModifier, filterPath, @@ -1568,6 +1592,7 @@ func TestValidateFilterResponseHeaderModifier(t *testing.T) { } func TestRouteKeyForKind(t *testing.T) { + t.Parallel() nsname := types.NamespacedName{Namespace: testNs, Name: "route"} g := NewWithT(t) diff --git a/internal/mode/static/state/graph/secret_test.go b/internal/mode/static/state/graph/secret_test.go index 54ebc3ca8a..79e9cf2578 100644 --- a/internal/mode/static/state/graph/secret_test.go +++ b/internal/mode/static/state/graph/secret_test.go @@ -67,6 +67,7 @@ cpLlHMAqbLJ8WYGJCkhiWxyal6hYTyWY4cVkC0xtTl/hUE9IeNKo ) func TestSecretResolver(t *testing.T) { + // t.Parallel() var ( validSecret1 = &apiv1.Secret{ ObjectMeta: metav1.ObjectMeta{ diff --git a/internal/mode/static/state/graph/service_test.go b/internal/mode/static/state/graph/service_test.go index 73e4851947..f857b7e425 100644 --- a/internal/mode/static/state/graph/service_test.go +++ b/internal/mode/static/state/graph/service_test.go @@ -8,6 +8,7 @@ import ( ) func TestBuildReferencedServices(t *testing.T) { + t.Parallel() normalRoute := &L7Route{ ParentRefs: []ParentRef{ { @@ -306,7 +307,9 @@ func TestBuildReferencedServices(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) g.Expect(buildReferencedServices(test.routes)).To(Equal(test.exp)) }) diff --git a/internal/mode/static/state/graph/validation_test.go b/internal/mode/static/state/graph/validation_test.go index d364adcf8f..5df1ad1cea 100644 --- a/internal/mode/static/state/graph/validation_test.go +++ b/internal/mode/static/state/graph/validation_test.go @@ -7,6 +7,7 @@ import ( ) func TestValidateHostname(t *testing.T) { + t.Parallel() tests := []struct { name string hostname string @@ -40,7 +41,9 @@ func TestValidateHostname(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) err := validateHostname(test.hostname) diff --git a/internal/mode/static/state/resolver/resolver_test.go b/internal/mode/static/state/resolver/resolver_test.go index 69c43e0240..91eaa238a6 100644 --- a/internal/mode/static/state/resolver/resolver_test.go +++ b/internal/mode/static/state/resolver/resolver_test.go @@ -83,6 +83,7 @@ var ( ) func TestFilterEndpointSliceList(t *testing.T) { + t.Parallel() sliceList := discoveryV1.EndpointSliceList{ Items: []discoveryV1.EndpointSlice{ validEndpointSlice, @@ -107,6 +108,7 @@ func TestFilterEndpointSliceList(t *testing.T) { } func TestGetDefaultPort(t *testing.T) { + t.Parallel() testcases := []struct { msg string svcPort v1.ServicePort @@ -144,6 +146,7 @@ func TestGetDefaultPort(t *testing.T) { } func TestIgnoreEndpointSlice(t *testing.T) { + t.Parallel() var ( port4000 int32 = 4000 port8080 int32 = 8080 @@ -252,6 +255,7 @@ func TestIgnoreEndpointSlice(t *testing.T) { } func TestEndpointReady(t *testing.T) { + t.Parallel() testcases := []struct { endpoint discoveryV1.Endpoint msg string @@ -292,6 +296,7 @@ func TestEndpointReady(t *testing.T) { } func TestFindPort(t *testing.T) { + t.Parallel() testcases := []struct { msg string ports []discoveryV1.EndpointPort @@ -424,6 +429,7 @@ func TestFindPort(t *testing.T) { } func TestCalculateReadyEndpoints(t *testing.T) { + t.Parallel() g := NewWithT(t) slices := []discoveryV1.EndpointSlice{ diff --git a/internal/mode/static/state/resolver/service_resolver_suite_test.go b/internal/mode/static/state/resolver/service_resolver_suite_test.go index ba1f845a4b..618aef434e 100644 --- a/internal/mode/static/state/resolver/service_resolver_suite_test.go +++ b/internal/mode/static/state/resolver/service_resolver_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestServiceResolver(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "ServiceResolver Suite") } diff --git a/internal/mode/static/state/state_suite_test.go b/internal/mode/static/state/state_suite_test.go index 4431b60a8e..058b439dae 100644 --- a/internal/mode/static/state/state_suite_test.go +++ b/internal/mode/static/state/state_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestState(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "State Suite") } diff --git a/internal/mode/static/state/store.go b/internal/mode/static/state/store.go index 163d051972..dd770f1722 100644 --- a/internal/mode/static/state/store.go +++ b/internal/mode/static/state/store.go @@ -19,7 +19,7 @@ type Updater interface { Delete(objType client.Object, nsname types.NamespacedName) } -// objectStore is a store of client.Object +// objectStore is a store of client.Object. type objectStore interface { get(objType client.Object, nsname types.NamespacedName) client.Object upsert(obj client.Object) @@ -296,7 +296,7 @@ func (s *changeTrackingUpdater) getAndResetChangedStatus() ChangeType { // - if no change occurred on this object, then keep the changeType as-is (could've been set by another object event) // - if changeType is already a ClusterStateChange, then we don't need to update the value // - otherwise, if we are processing an Endpoint update, then this is an EndpointsOnlyChange changeType -// - otherwise, this is a different object, and is a ClusterStateChange changeType +// - otherwise, this is a different object, and is a ClusterStateChange changeType. func (s *changeTrackingUpdater) setChangeType(obj client.Object, changed bool) { if changed && s.changeType != ClusterStateChange { if _, ok := obj.(*discoveryV1.EndpointSlice); ok { diff --git a/internal/mode/static/state/store_test.go b/internal/mode/static/state/store_test.go index b4184d3154..13113e97aa 100644 --- a/internal/mode/static/state/store_test.go +++ b/internal/mode/static/state/store_test.go @@ -10,6 +10,7 @@ import ( ) func TestSetChangeType(t *testing.T) { + // t.Parallel() ctu := newChangeTrackingUpdater(nil, nil) // Order matters for these cases. @@ -44,7 +45,9 @@ func TestSetChangeType(t *testing.T) { } for _, test := range tests { + // test := test t.Run(test.name, func(t *testing.T) { + // t.Parallel() g := NewWithT(t) ctu.setChangeType(test.obj, test.changed) g.Expect(ctu.changeType).To(Equal(test.exp)) diff --git a/internal/mode/static/static_suite_test.go b/internal/mode/static/static_suite_test.go index 95fafaeec7..0d47b11d5b 100644 --- a/internal/mode/static/static_suite_test.go +++ b/internal/mode/static/static_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestStatic(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Static Suite") } diff --git a/internal/mode/static/status/prepare_requests_test.go b/internal/mode/static/status/prepare_requests_test.go index 407aff11e1..184f25fc40 100644 --- a/internal/mode/static/status/prepare_requests_test.go +++ b/internal/mode/static/status/prepare_requests_test.go @@ -210,6 +210,7 @@ var ( ) func TestBuildHTTPRouteStatuses(t *testing.T) { + t.Parallel() hrValid := &v1.HTTPRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", @@ -282,6 +283,7 @@ func TestBuildHTTPRouteStatuses(t *testing.T) { } func TestBuildGRPCRouteStatuses(t *testing.T) { + t.Parallel() grValid := &v1.GRPCRoute{ ObjectMeta: metav1.ObjectMeta{ Namespace: "test", @@ -354,6 +356,7 @@ func TestBuildGRPCRouteStatuses(t *testing.T) { } func TestBuildRouteStatusesNginxErr(t *testing.T) { + t.Parallel() const gatewayCtlrName = "controller" hr1 := &v1.HTTPRoute{ @@ -454,6 +457,7 @@ func TestBuildRouteStatusesNginxErr(t *testing.T) { } func TestBuildGatewayClassStatuses(t *testing.T) { + t.Parallel() transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now()) tests := []struct { @@ -545,7 +549,9 @@ func TestBuildGatewayClassStatuses(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) k8sClient := createK8sClientFor(&v1.GatewayClass{}) @@ -584,6 +590,7 @@ func TestBuildGatewayClassStatuses(t *testing.T) { } func TestBuildGatewayStatuses(t *testing.T) { + t.Parallel() createGateway := func() *v1.Gateway { return &v1.Gateway{ ObjectMeta: metav1.ObjectMeta{ @@ -1038,7 +1045,9 @@ func TestBuildGatewayStatuses(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) k8sClient := createK8sClientFor(&v1.Gateway{}) @@ -1084,6 +1093,7 @@ func TestBuildGatewayStatuses(t *testing.T) { } func TestBuildBackendTLSPolicyStatuses(t *testing.T) { + t.Parallel() const gatewayCtlrName = "controller" transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now()) @@ -1264,7 +1274,9 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) k8sClient := createK8sClientFor(&v1alpha3.BackendTLSPolicy{}) @@ -1294,6 +1306,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) { } func TestBuildNginxGatewayStatus(t *testing.T) { + t.Parallel() transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now()) tests := []struct { @@ -1356,7 +1369,9 @@ func TestBuildNginxGatewayStatus(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) k8sClient := createK8sClientFor(&ngfAPI.NginxGateway{}) @@ -1387,6 +1402,7 @@ func TestBuildNginxGatewayStatus(t *testing.T) { } func TestBuildNGFPolicyStatuses(t *testing.T) { + t.Parallel() const gatewayCtlrName = "controller" transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now()) @@ -1648,7 +1664,9 @@ func TestBuildNGFPolicyStatuses(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) k8sClient := createK8sClientFor(&ngfAPI.ClientSettingsPolicy{}) diff --git a/internal/mode/static/status/status_setters_test.go b/internal/mode/static/status/status_setters_test.go index a7b838342d..490eb4207d 100644 --- a/internal/mode/static/status/status_setters_test.go +++ b/internal/mode/static/status/status_setters_test.go @@ -16,6 +16,7 @@ import ( ) func TestNewNginxGatewayStatusSetter(t *testing.T) { + t.Parallel() tests := []struct { name string status, newStatus ngfAPI.NginxGatewayStatus @@ -52,7 +53,9 @@ func TestNewNginxGatewayStatusSetter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) setter := newNginxGatewayStatusSetter(test.newStatus) @@ -67,6 +70,7 @@ func TestNewNginxGatewayStatusSetter(t *testing.T) { } func TestNewGatewayStatusSetter(t *testing.T) { + t.Parallel() expAddress := gatewayv1.GatewayStatusAddress{ Type: helpers.GetPointer(gatewayv1.IPAddressType), Value: "10.0.0.0", @@ -113,7 +117,9 @@ func TestNewGatewayStatusSetter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) setter := newGatewayStatusSetter(test.newStatus) @@ -128,6 +134,7 @@ func TestNewGatewayStatusSetter(t *testing.T) { } func TestNewHTTPRouteStatusSetter(t *testing.T) { + t.Parallel() const ( controllerName = "controller" otherControllerName = "different" @@ -288,7 +295,9 @@ func TestNewHTTPRouteStatusSetter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) setter := newHTTPRouteStatusSetter(test.newStatus, controllerName) @@ -303,6 +312,7 @@ func TestNewHTTPRouteStatusSetter(t *testing.T) { } func TestNewGRPCRouteStatusSetter(t *testing.T) { + t.Parallel() const ( controllerName = "controller" otherControllerName = "different" @@ -463,7 +473,9 @@ func TestNewGRPCRouteStatusSetter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) setter := newGRPCRouteStatusSetter(test.newStatus, controllerName) @@ -478,6 +490,7 @@ func TestNewGRPCRouteStatusSetter(t *testing.T) { } func TestNewGatewayClassStatusSetter(t *testing.T) { + t.Parallel() tests := []struct { name string status, newStatus gatewayv1.GatewayClassStatus @@ -513,7 +526,9 @@ func TestNewGatewayClassStatusSetter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) setter := newGatewayClassStatusSetter(test.newStatus) @@ -528,6 +543,7 @@ func TestNewGatewayClassStatusSetter(t *testing.T) { } func TestNewBackendTLSPolicyStatusSetter(t *testing.T) { + t.Parallel() const ( controllerName = "controller" otherControllerName = "other-controller" @@ -653,7 +669,9 @@ func TestNewBackendTLSPolicyStatusSetter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) setter := newBackendTLSPolicyStatusSetter(test.newStatus, controllerName) @@ -668,6 +686,7 @@ func TestNewBackendTLSPolicyStatusSetter(t *testing.T) { } func TestNewNGFPolicyStatusSetter(t *testing.T) { + t.Parallel() const ( controllerName = "controller" otherControllerName = "other-controller" @@ -793,7 +812,9 @@ func TestNewNGFPolicyStatusSetter(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) setter := newNGFPolicyStatusSetter(test.newStatus, controllerName) @@ -815,6 +836,7 @@ func TestNewNGFPolicyStatusSetter(t *testing.T) { } func TestGWStatusEqual(t *testing.T) { + t.Parallel() getDefaultStatus := func() gatewayv1.GatewayStatus { return gatewayv1.GatewayStatus{ Addresses: []gatewayv1.GatewayStatusAddress{ @@ -1004,7 +1026,9 @@ func TestGWStatusEqual(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) equal := gwStatusEqual(test.prevStatus, test.curStatus) @@ -1014,6 +1038,7 @@ func TestGWStatusEqual(t *testing.T) { } func TestHRStatusEqual(t *testing.T) { + t.Parallel() testConds := []metav1.Condition{ { Type: "type", /* conditions are covered by another test*/ @@ -1141,7 +1166,9 @@ func TestHRStatusEqual(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) equal := routeStatusEqual("ours", test.prevStatus.Parents, test.curStatus.Parents) g.Expect(equal).To(Equal(test.expEqual)) @@ -1150,6 +1177,7 @@ func TestHRStatusEqual(t *testing.T) { } func TestRouteParentStatusEqual(t *testing.T) { + t.Parallel() getDefaultStatus := func() gatewayv1.RouteParentStatus { return gatewayv1.RouteParentStatus{ ParentRef: gatewayv1.ParentReference{ @@ -1232,7 +1260,9 @@ func TestRouteParentStatusEqual(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) equal := routeParentStatusEqual(test.p1, test.p2) g.Expect(equal).To(Equal(test.expEqual)) @@ -1241,6 +1271,7 @@ func TestRouteParentStatusEqual(t *testing.T) { } func TestPolicyStatusEqual(t *testing.T) { + t.Parallel() getPolicyStatus := func() v1alpha2.PolicyStatus { return v1alpha2.PolicyStatus{ Ancestors: []v1alpha2.PolicyAncestorStatus{ @@ -1381,7 +1412,9 @@ func TestPolicyStatusEqual(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) equal := policyStatusEqual(test.controllerName, test.previous, test.current) g.Expect(equal).To(Equal(test.expEqual)) diff --git a/internal/mode/static/telemetry/data_test.go b/internal/mode/static/telemetry/data_test.go index a8285fc8f2..e52af3f86d 100644 --- a/internal/mode/static/telemetry/data_test.go +++ b/internal/mode/static/telemetry/data_test.go @@ -9,6 +9,7 @@ import ( ) func TestDataAttributes(t *testing.T) { + t.Parallel() data := Data{ ImageSource: "local", Data: tel.Data{ @@ -67,6 +68,7 @@ func TestDataAttributes(t *testing.T) { } func TestDataAttributesWithEmptyData(t *testing.T) { + t.Parallel() data := Data{} expected := []attribute.KeyValue{ diff --git a/internal/mode/static/telemetry/exporter_test.go b/internal/mode/static/telemetry/exporter_test.go index 6a86a01685..d44a7d2e24 100644 --- a/internal/mode/static/telemetry/exporter_test.go +++ b/internal/mode/static/telemetry/exporter_test.go @@ -10,6 +10,7 @@ import ( ) func TestLoggingExporter(t *testing.T) { + t.Parallel() g := NewWithT(t) var buffer bytes.Buffer diff --git a/internal/mode/static/telemetry/job_worker_test.go b/internal/mode/static/telemetry/job_worker_test.go index 88cc7fbc4c..1425fc3970 100644 --- a/internal/mode/static/telemetry/job_worker_test.go +++ b/internal/mode/static/telemetry/job_worker_test.go @@ -15,6 +15,7 @@ import ( ) func TestCreateTelemetryJobWorker_Succeeds(t *testing.T) { + t.Parallel() g := NewWithT(t) exporter := &telemetryfakes.FakeExporter{} @@ -39,6 +40,7 @@ func TestCreateTelemetryJobWorker_Succeeds(t *testing.T) { } func TestCreateTelemetryJobWorker_CollectFails(t *testing.T) { + t.Parallel() g := NewWithT(t) exporter := &telemetryfakes.FakeExporter{} diff --git a/internal/mode/static/telemetry/platform_test.go b/internal/mode/static/telemetry/platform_test.go index 0c2939d820..0f345f9f70 100644 --- a/internal/mode/static/telemetry/platform_test.go +++ b/internal/mode/static/telemetry/platform_test.go @@ -9,6 +9,7 @@ import ( ) func TestGetPlatform(t *testing.T) { + t.Parallel() tests := []struct { node *v1.Node namespaces *v1.NamespaceList @@ -127,7 +128,9 @@ func TestGetPlatform(t *testing.T) { }, } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) platform := getPlatform(*test.node, *test.namespaces) diff --git a/internal/mode/static/telemetry/telemetry_suite_test.go b/internal/mode/static/telemetry/telemetry_suite_test.go index 2eae64e153..2f5a50adb4 100644 --- a/internal/mode/static/telemetry/telemetry_suite_test.go +++ b/internal/mode/static/telemetry/telemetry_suite_test.go @@ -8,6 +8,7 @@ import ( ) func TestTelemetry(t *testing.T) { + t.Parallel() RegisterFailHandler(Fail) RunSpecs(t, "Telemetry Suite") } diff --git a/internal/mode/static/usage/job_worker_test.go b/internal/mode/static/usage/job_worker_test.go index c94bf15698..4aa7591f4a 100644 --- a/internal/mode/static/usage/job_worker_test.go +++ b/internal/mode/static/usage/job_worker_test.go @@ -22,6 +22,7 @@ import ( ) func TestCreateUsageJobWorker(t *testing.T) { + t.Parallel() replicas := int32(1) ngfReplicaSet := &appsv1.ReplicaSet{ ObjectMeta: metav1.ObjectMeta{ @@ -138,7 +139,9 @@ func TestCreateUsageJobWorker(t *testing.T) { } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { + t.Parallel() g := NewWithT(t) k8sClientReader := &eventsfakes.FakeReader{} @@ -178,6 +181,7 @@ func TestCreateUsageJobWorker(t *testing.T) { } func TestGetTotalNGFPodCount(t *testing.T) { + t.Parallel() g := NewWithT(t) rs1Replicas := int32(1) @@ -241,6 +245,7 @@ func TestGetTotalNGFPodCount(t *testing.T) { } func TestCollectNodeCount(t *testing.T) { + t.Parallel() g := NewWithT(t) node1 := &v1.Node{ diff --git a/internal/mode/static/usage/reporter_test.go b/internal/mode/static/usage/reporter_test.go index 5099dfb591..dff1866bc5 100644 --- a/internal/mode/static/usage/reporter_test.go +++ b/internal/mode/static/usage/reporter_test.go @@ -13,6 +13,7 @@ import ( ) func TestReport(t *testing.T) { + t.Parallel() g := NewWithT(t) data := ClusterDetails{ @@ -68,6 +69,7 @@ func TestReport(t *testing.T) { } func TestReport_NoCredentials(t *testing.T) { + t.Parallel() g := NewWithT(t) insecureSkipVerify := false reporter, err := NewNIMReporter(NewUsageSecret(), "", insecureSkipVerify) @@ -79,6 +81,7 @@ func TestReport_NoCredentials(t *testing.T) { } func TestReport_ServerError(t *testing.T) { + t.Parallel() g := NewWithT(t) server := httptest.NewServer( diff --git a/internal/mode/static/usage/secret_test.go b/internal/mode/static/usage/secret_test.go index 0320c72c16..82a5abd886 100644 --- a/internal/mode/static/usage/secret_test.go +++ b/internal/mode/static/usage/secret_test.go @@ -9,6 +9,7 @@ import ( ) func TestSet(t *testing.T) { + t.Parallel() store := NewUsageSecret() secret := &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -25,6 +26,7 @@ func TestSet(t *testing.T) { } func TestDelete(t *testing.T) { + t.Parallel() store := NewUsageSecret() secret := &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ @@ -42,6 +44,7 @@ func TestDelete(t *testing.T) { } func TestGetCredentials(t *testing.T) { + t.Parallel() store := NewUsageSecret() secret := &v1.Secret{ ObjectMeta: metav1.ObjectMeta{ diff --git a/tests/framework/load.go b/tests/framework/load.go index db3b84c7ac..c687f275b1 100644 --- a/tests/framework/load.go +++ b/tests/framework/load.go @@ -47,7 +47,7 @@ type Metrics struct { } // RunLoadTest uses Vegeta to send traffic to the provided Targets at the given rate for the given duration and writes -// the results to the provided file +// the results to the provided file. func RunLoadTest(cfg LoadTestConfig) (vegeta.Results, Metrics) { vegTargets := convertTargetToVegetaTarget(cfg.Targets) targeter := vegeta.NewStaticTargeter(vegTargets...) diff --git a/tests/framework/prometheus.go b/tests/framework/prometheus.go index caec955443..76c75641fc 100644 --- a/tests/framework/prometheus.go +++ b/tests/framework/prometheus.go @@ -24,7 +24,7 @@ const ( var defaultPrometheusQueryTimeout = 2 * time.Second -// PrometheusConfig is the configuration for installing Prometheus +// PrometheusConfig is the configuration for installing Prometheus. type PrometheusConfig struct { // ScrapeInterval is the interval at which Prometheus scrapes metrics. ScrapeInterval time.Duration diff --git a/tests/framework/resourcemanager.go b/tests/framework/resourcemanager.go index 3612c7af34..db98e34067 100644 --- a/tests/framework/resourcemanager.go +++ b/tests/framework/resourcemanager.go @@ -54,7 +54,7 @@ type ResourceManager struct { TimeoutConfig TimeoutConfig } -// ClusterInfo holds the cluster metadata +// ClusterInfo holds the cluster metadata. type ClusterInfo struct { K8sVersion string // ID is the UID of kube-system namespace @@ -475,7 +475,7 @@ func (rm *ResourceManager) waitForLBStatusToBeReady(ctx context.Context, svcNsNa ) } -// GetClusterInfo retrieves node info and Kubernetes version from the cluster +// GetClusterInfo retrieves node info and Kubernetes version from the cluster. func (rm *ResourceManager) GetClusterInfo() (ClusterInfo, error) { ctx, cancel := context.WithTimeout(context.Background(), rm.TimeoutConfig.GetTimeout) defer cancel() @@ -568,7 +568,7 @@ func (rm *ResourceManager) GetPod(namespace, name string) (*core.Pod, error) { return &pod, nil } -// GetPodLogs returns the logs from the specified Pod +// GetPodLogs returns the logs from the specified Pod. func (rm *ResourceManager) GetPodLogs(namespace, name string, opts *core.PodLogOptions) (string, error) { ctx, cancel := context.WithTimeout(context.Background(), rm.TimeoutConfig.GetTimeout) defer cancel() diff --git a/tests/suite/system_suite_test.go b/tests/suite/system_suite_test.go index ab927649fd..4b69823dc5 100644 --- a/tests/suite/system_suite_test.go +++ b/tests/suite/system_suite_test.go @@ -34,6 +34,7 @@ import ( ) func TestNGF(t *testing.T) { + t.Parallel() flag.Parse() if *gatewayAPIVersion == "" { panic("Gateway API version must be set")