Skip to content

Run tests in internal/mode/static/nginx/config in parallel (1) #2493

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -149,9 +150,9 @@ func TestGenerate(t *testing.T) {
},
}

g := NewWithT(t)

checkResults := func(resFiles policies.GenerateResultFiles, expStrings []string) {
checkResults := func(t *testing.T, resFiles policies.GenerateResultFiles, expStrings []string) {
t.Helper()
g := NewWithT(t)
g.Expect(resFiles).To(HaveLen(1))

for _, str := range expStrings {
Expand All @@ -160,22 +161,24 @@ func TestGenerate(t *testing.T) {
}

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

resFiles := generator.GenerateForServer([]policies.Policy{test.policy}, http.Server{})
checkResults(resFiles, test.expStrings)
checkResults(t, resFiles, test.expStrings)

resFiles = generator.GenerateForLocation([]policies.Policy{test.policy}, http.Location{})
checkResults(resFiles, test.expStrings)
checkResults(t, resFiles, test.expStrings)

resFiles = generator.GenerateForInternalLocation([]policies.Policy{test.policy})
checkResults(resFiles, test.expStrings)
checkResults(t, resFiles, test.expStrings)
})
}
}

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

generator := clientsettings.NewGenerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -133,6 +134,7 @@ func TestValidator_Validate(t *testing.T) {

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

conds := v.Validate(test.policy, nil)
Expand All @@ -142,6 +144,7 @@ func TestValidator_Validate(t *testing.T) {
}

func TestValidator_ValidatePanics(t *testing.T) {
t.Parallel()
v := clientsettings.NewValidator(nil)

validate := func() {
Expand All @@ -154,6 +157,7 @@ func TestValidator_ValidatePanics(t *testing.T) {
}

func TestValidator_Conflicts(t *testing.T) {
t.Parallel()
tests := []struct {
polA *ngfAPI.ClientSettingsPolicy
polB *ngfAPI.ClientSettingsPolicy
Expand Down Expand Up @@ -256,6 +260,7 @@ func TestValidator_Conflicts(t *testing.T) {

for _, test := range tests {
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))
Expand All @@ -264,6 +269,7 @@ func TestValidator_Conflicts(t *testing.T) {
}

func TestValidator_ConflictsPanics(t *testing.T) {
t.Parallel()
v := clientsettings.NewValidator(nil)

conflicts := func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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)
Expand Down Expand Up @@ -242,6 +243,7 @@ func TestGenerate(t *testing.T) {

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

generator := observability.NewGenerator(test.telemetryConf)
Expand Down Expand Up @@ -280,6 +282,7 @@ func TestGenerate(t *testing.T) {
}

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

generator := observability.NewGenerator(dataplane.Telemetry{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -185,6 +186,7 @@ func TestValidator_Validate(t *testing.T) {

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

conds := v.Validate(test.policy, test.globalSettings)
Expand All @@ -194,6 +196,7 @@ func TestValidator_Validate(t *testing.T) {
}

func TestValidator_ValidatePanics(t *testing.T) {
t.Parallel()
v := observability.NewValidator(nil)

validate := func() {
Expand All @@ -206,6 +209,7 @@ func TestValidator_ValidatePanics(t *testing.T) {
}

func TestValidator_Conflicts(t *testing.T) {
t.Parallel()
tests := []struct {
polA *ngfAPI.ObservabilityPolicy
polB *ngfAPI.ObservabilityPolicy
Expand Down Expand Up @@ -244,6 +248,7 @@ func TestValidator_Conflicts(t *testing.T) {

for _, test := range tests {
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))
Expand All @@ -252,6 +257,7 @@ func TestValidator_Conflicts(t *testing.T) {
}

func TestValidator_ConflictsPanics(t *testing.T) {
t.Parallel()
v := observability.NewValidator(nil)

conflicts := func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestPolicies(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
RunSpecs(t, "Policies Suite")
}
3 changes: 3 additions & 0 deletions internal/mode/static/nginx/config/validation/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

func TestValidateEscapedString(t *testing.T) {
t.Parallel()
validator := func(value string) error { return validateEscapedString(value, []string{"example"}) }

testValidValuesForSimpleValidator(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func testInvalidValuesForSupportedValuesValidator[T configValue](
}

func TestValidateInSupportedValues(t *testing.T) {
t.Parallel()
supportedValues := map[string]struct{}{
"value1": {},
"value2": {},
Expand All @@ -105,6 +106,7 @@ func TestValidateInSupportedValues(t *testing.T) {
}

func TestValidateNoUnsupportedValues(t *testing.T) {
t.Parallel()
unsupportedValues := map[string]struct{}{
"badvalue1": {},
"badvalue2": {},
Expand Down Expand Up @@ -133,6 +135,7 @@ func TestValidateNoUnsupportedValues(t *testing.T) {
}

func TestGetSortedKeysAsString(t *testing.T) {
t.Parallel()
values := map[string]struct{}{
"value3": {},
"value1": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package validation
import "testing"

func TestGenericValidator_ValidateEscapedStringNoVarExpansion(t *testing.T) {
t.Parallel()
validator := GenericValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -24,6 +25,7 @@ func TestGenericValidator_ValidateEscapedStringNoVarExpansion(t *testing.T) {
}

func TestValidateServiceName(t *testing.T) {
t.Parallel()
validator := GenericValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -45,6 +47,7 @@ func TestValidateServiceName(t *testing.T) {
}

func TestValidateNginxDuration(t *testing.T) {
t.Parallel()
validator := GenericValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -65,6 +68,7 @@ func TestValidateNginxDuration(t *testing.T) {
}

func TestValidateNginxSize(t *testing.T) {
t.Parallel()
validator := GenericValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -86,6 +90,7 @@ func TestValidateNginxSize(t *testing.T) {
}

func TestValidateEndpoint(t *testing.T) {
t.Parallel()
validator := GenericValidator{}

testValidValuesForSimpleValidator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

func TestValidateRedirectScheme(t *testing.T) {
t.Parallel()
validator := HTTPRedirectValidator{}

testValidValuesForSupportedValuesValidator(
Expand All @@ -24,6 +25,7 @@ func TestValidateRedirectScheme(t *testing.T) {
}

func TestValidateRedirectPort(t *testing.T) {
t.Parallel()
validator := HTTPRedirectValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -35,6 +37,7 @@ func TestValidateRedirectPort(t *testing.T) {
}

func TestValidateRedirectStatusCode(t *testing.T) {
t.Parallel()
validator := HTTPRedirectValidator{}

testValidValuesForSupportedValuesValidator(
Expand All @@ -52,6 +55,7 @@ func TestValidateRedirectStatusCode(t *testing.T) {
}

func TestValidateHostname(t *testing.T) {
t.Parallel()
validator := HTTPRedirectValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -68,6 +72,7 @@ func TestValidateHostname(t *testing.T) {
}

func TestValidateRewritePath(t *testing.T) {
t.Parallel()
validator := HTTPURLRewriteValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -89,6 +94,7 @@ func TestValidateRewritePath(t *testing.T) {
}

func TestValidateFilterHeaderName(t *testing.T) {
t.Parallel()
validator := HTTPHeaderValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -102,6 +108,7 @@ func TestValidateFilterHeaderName(t *testing.T) {
}

func TestValidateFilterHeaderValue(t *testing.T) {
t.Parallel()
validator := HTTPHeaderValidator{}

testValidValuesForSimpleValidator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

func TestValidatePathInMatch(t *testing.T) {
t.Parallel()
validator := HTTPNJSMatchValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -28,6 +29,7 @@ func TestValidatePathInMatch(t *testing.T) {
}

func TestValidateHeaderNameInMatch(t *testing.T) {
t.Parallel()
validator := HTTPNJSMatchValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -50,6 +52,7 @@ func TestValidateHeaderNameInMatch(t *testing.T) {
}

func TestValidateHeaderValueInMatch(t *testing.T) {
t.Parallel()
validator := HTTPNJSMatchValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -70,6 +73,7 @@ func TestValidateHeaderValueInMatch(t *testing.T) {
}

func TestValidateQueryParamNameInMatch(t *testing.T) {
t.Parallel()
validator := HTTPNJSMatchValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -85,6 +89,7 @@ func TestValidateQueryParamNameInMatch(t *testing.T) {
}

func TestValidateQueryParamValueInMatch(t *testing.T) {
t.Parallel()
validator := HTTPNJSMatchValidator{}

testValidValuesForSimpleValidator(
Expand All @@ -100,6 +105,7 @@ func TestValidateQueryParamValueInMatch(t *testing.T) {
}

func TestValidateMethodInMatch(t *testing.T) {
t.Parallel()
validator := HTTPNJSMatchValidator{}

testValidValuesForSupportedValuesValidator(
Expand All @@ -123,6 +129,7 @@ func TestValidateMethodInMatch(t *testing.T) {
}

func TestValidateCommonMatchPart(t *testing.T) {
t.Parallel()
testValidValuesForSimpleValidator(
t,
validateCommonNJSMatchPart,
Expand Down
Loading