Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make TransportServer tests run in parallel #3892

Merged
merged 1 commit into from
May 15, 2023
Merged
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
103 changes: 74 additions & 29 deletions pkg/apis/configuration/validation/transportserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func createTransportServerValidator() *TransportServerValidator {

func TestValidateTransportServer(t *testing.T) {
t.Parallel()

ts := v1alpha1.TransportServer{
Spec: v1alpha1.TransportServerSpec{
Listener: v1alpha1.TransportServerListener{
Expand Down Expand Up @@ -41,7 +42,7 @@ func TestValidateTransportServer(t *testing.T) {
}
}

func TestValidateTransportServerFails(t *testing.T) {
func TestValidateTransportServer_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
ts := v1alpha1.TransportServer{
Spec: v1alpha1.TransportServerSpec{
Expand Down Expand Up @@ -69,6 +70,7 @@ func TestValidateTransportServerFails(t *testing.T) {
}

func TestValidateTransportServerUpstreams(t *testing.T) {
t.Parallel()
tests := []struct {
upstreams []v1alpha1.Upstream
expectedUpstreamNames sets.Set[string]
Expand Down Expand Up @@ -103,15 +105,16 @@ func TestValidateTransportServerUpstreams(t *testing.T) {
for _, test := range tests {
allErrs, resultUpstreamNames := validateTransportServerUpstreams(test.upstreams, field.NewPath("upstreams"), true)
if len(allErrs) > 0 {
t.Errorf("validateTransportServerUpstreams() returned errors %v for valid input for the case of %s", allErrs, test.msg)
t.Fatalf("validateTransportServerUpstreams() returned errors %v for valid input for the case of %s", allErrs, test.msg)
}
if !resultUpstreamNames.Equal(test.expectedUpstreamNames) {
t.Errorf("validateTransportServerUpstreams() returned %v expected %v for the case of %s", resultUpstreamNames, test.expectedUpstreamNames, test.msg)
}
}
}

func TestValidateTransportServerUpstreamsFails(t *testing.T) {
func TestValidateTransportServerUpstreams_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
tests := []struct {
upstreams []v1alpha1.Upstream
expectedUpstreamNames sets.Set[string]
Expand Down Expand Up @@ -177,7 +180,7 @@ func TestValidateTransportServerUpstreamsFails(t *testing.T) {
for _, test := range tests {
allErrs, resultUpstreamNames := validateTransportServerUpstreams(test.upstreams, field.NewPath("upstreams"), true)
if len(allErrs) == 0 {
t.Errorf("validateTransportServerUpstreams() returned no errors for the case of %s", test.msg)
t.Fatalf("validateTransportServerUpstreams() returned no errors for the case of %s", test.msg)
}
if !resultUpstreamNames.Equal(test.expectedUpstreamNames) {
t.Errorf("validateTransportServerUpstreams() returned %v expected %v for the case of %s", resultUpstreamNames, test.expectedUpstreamNames, test.msg)
Expand All @@ -186,6 +189,7 @@ func TestValidateTransportServerUpstreamsFails(t *testing.T) {
}

func TestValidateTransportServerHost(t *testing.T) {
t.Parallel()
tests := []struct {
host string
isTLSPassthroughListener bool
Expand All @@ -209,6 +213,8 @@ func TestValidateTransportServerHost(t *testing.T) {
}

func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
t.Parallel()

tests := []struct {
method string
isPlus bool
Expand Down Expand Up @@ -314,7 +320,7 @@ func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
for _, test := range tests {
allErrs := validateLoadBalancingMethod(test.method, field.NewPath("method"), test.isPlus)
if !test.hasError && len(allErrs) > 0 {
t.Errorf("validateLoadBalancingMethod(%q, %v) returned errors %v for valid input", test.method, test.isPlus, allErrs)
t.Fatalf("validateLoadBalancingMethod(%q, %v) returned errors %v for valid input", test.method, test.isPlus, allErrs)
}
if test.hasError && len(allErrs) < 1 {
t.Errorf("validateLoadBalancingMethod(%q, %v) failed to return an error for invalid input", test.method, test.isPlus)
Expand All @@ -323,6 +329,7 @@ func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
}

func TestValidateTransportServerSnippet(t *testing.T) {
t.Parallel()
tests := []struct {
snippet string
isSnippetsEnabled bool
Expand Down Expand Up @@ -359,7 +366,8 @@ func TestValidateTransportServerSnippet(t *testing.T) {
}
}

func TestValidateTransportServerHostFails(t *testing.T) {
func TestValidateTransportServerHost_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
tests := []struct {
host string
isTLSPassthroughListener bool
Expand All @@ -383,6 +391,7 @@ func TestValidateTransportServerHostFails(t *testing.T) {
}

func TestValidateTransportListener(t *testing.T) {
t.Parallel()
tests := []struct {
listener *v1alpha1.TransportServerListener
tlsPassthrough bool
Expand Down Expand Up @@ -422,7 +431,8 @@ func TestValidateTransportListener(t *testing.T) {
}
}

func TestValidateTransportListenerFails(t *testing.T) {
func TestValidateTransportListener_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
tests := []struct {
listener *v1alpha1.TransportServerListener
tlsPassthrough bool
Expand Down Expand Up @@ -477,6 +487,7 @@ func TestValidateTransportListenerFails(t *testing.T) {
}

func TestValidateIsPotentialTLSPassthroughListener(t *testing.T) {
t.Parallel()
tests := []struct {
listener *v1alpha1.TransportServerListener
expected bool
Expand Down Expand Up @@ -513,6 +524,7 @@ func TestValidateIsPotentialTLSPassthroughListener(t *testing.T) {
}

func TestValidateListenerProtocol(t *testing.T) {
t.Parallel()
validProtocols := []string{
"TCP",
"UDP",
Expand All @@ -524,7 +536,10 @@ func TestValidateListenerProtocol(t *testing.T) {
t.Errorf("validateListenerProtocol(%q) returned errors %v for valid input", p, allErrs)
}
}
}

func TestValidateListenerProtocol_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
invalidProtocols := []string{
"",
"HTTP",
Expand All @@ -541,6 +556,7 @@ func TestValidateListenerProtocol(t *testing.T) {
}

func TestValidateTSUpstreamHealthChecks(t *testing.T) {
t.Parallel()
tests := []struct {
healthCheck *v1alpha1.HealthCheck
msg string
Expand Down Expand Up @@ -574,7 +590,8 @@ func TestValidateTSUpstreamHealthChecks(t *testing.T) {
}
}

func TestValidateTSUpstreamHealthChecksFails(t *testing.T) {
func TestValidateTSUpstreamHealthChecks_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
tests := []struct {
healthCheck *v1alpha1.HealthCheck
msg string
Expand Down Expand Up @@ -662,6 +679,7 @@ func TestValidateTSUpstreamHealthChecksFails(t *testing.T) {
}

func TestValidateUpstreamParameters(t *testing.T) {
t.Parallel()
tests := []struct {
parameters *v1alpha1.UpstreamParameters
msg string
Expand All @@ -685,6 +703,7 @@ func TestValidateUpstreamParameters(t *testing.T) {
}

func TestValidateSessionParameters(t *testing.T) {
t.Parallel()
tests := []struct {
parameters *v1alpha1.SessionParameters
msg string
Expand Down Expand Up @@ -713,7 +732,8 @@ func TestValidateSessionParameters(t *testing.T) {
}
}

func TestValidateSessionParametersFails(t *testing.T) {
func TestValidateSessionParameters_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
tests := []struct {
parameters *v1alpha1.SessionParameters
msg string
Expand All @@ -735,6 +755,7 @@ func TestValidateSessionParametersFails(t *testing.T) {
}

func TestValidateUDPUpstreamParameter(t *testing.T) {
t.Parallel()
validInput := []struct {
parameter *int
protocol string
Expand Down Expand Up @@ -765,7 +786,8 @@ func TestValidateUDPUpstreamParameter(t *testing.T) {
}
}

func TestValidateUDPUpstreamParameterFails(t *testing.T) {
func TestValidateUDPUpstreamParameter_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
invalidInput := []struct {
parameter *int
protocol string
Expand All @@ -789,6 +811,7 @@ func TestValidateUDPUpstreamParameterFails(t *testing.T) {
}

func TestValidateTransportServerAction(t *testing.T) {
t.Parallel()
upstreamNames := map[string]sets.Empty{
"test": {},
}
Expand All @@ -803,7 +826,8 @@ func TestValidateTransportServerAction(t *testing.T) {
}
}

func TestValidateTransportServerActionFails(t *testing.T) {
func TestValidateTransportServerAction_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
upstreamNames := map[string]sets.Empty{}

tests := []struct {
Expand Down Expand Up @@ -833,23 +857,29 @@ func TestValidateTransportServerActionFails(t *testing.T) {
}

func TestValidateMatchSend(t *testing.T) {
t.Parallel()
validInput := []string{
"",
"abc",
"hello${world}",
`hello\x00`,
}
invalidInput := []string{
`hello"world`,
`\x1x`,
}

for _, send := range validInput {
allErrs := validateMatchSend(send, field.NewPath("send"))
if len(allErrs) > 0 {
t.Errorf("validateMatchSend(%q) returned errors %v for valid input", send, allErrs)
}
}
}

func TestValidateMatchSend_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
invalidInput := []string{
`hello"world`,
`\x1x`,
}

for _, send := range invalidInput {
allErrs := validateMatchSend(send, field.NewPath("send"))
if len(allErrs) == 0 {
Expand All @@ -859,6 +889,7 @@ func TestValidateMatchSend(t *testing.T) {
}

func TestValidateHexString(t *testing.T) {
t.Parallel()
validInput := []string{
"",
"abc",
Expand All @@ -868,6 +899,17 @@ func TestValidateHexString(t *testing.T) {
`\xff`,
`\xaaFFabc\x12`,
}

for _, s := range validInput {
err := validateHexString(s)
if err != nil {
t.Errorf("validateHexString(%q) returned error %v for valid input", s, err)
}
}
}

func TestValidateHexString_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
invalidInput := []string{
`\x`,
`\x1`,
Expand All @@ -876,12 +918,6 @@ func TestValidateHexString(t *testing.T) {
`\xaaFFabc\xx12`, // \xx1 is invalid
}

for _, s := range validInput {
err := validateHexString(s)
if err != nil {
t.Errorf("validateHexString(%q) returned error %v for valid input", s, err)
}
}
for _, s := range invalidInput {
err := validateHexString(s)
if err == nil {
Expand All @@ -891,6 +927,7 @@ func TestValidateHexString(t *testing.T) {
}

func TestValidateMatchExpect(t *testing.T) {
t.Parallel()
validInput := []string{
``,
`abc`,
Expand All @@ -900,6 +937,17 @@ func TestValidateMatchExpect(t *testing.T) {
`~`,
`~*`,
}

for _, input := range validInput {
allErrs := validateMatchExpect(input, field.NewPath("expect"))
if len(allErrs) > 0 {
t.Errorf("validateMatchExpect(%q) returned errors %v for valid input", input, allErrs)
}
}
}

func TestValidateMatchExpect_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
invalidInput := []string{
`hello"world`,
`~hello"world`,
Expand All @@ -911,12 +959,6 @@ func TestValidateMatchExpect(t *testing.T) {
`~{1}`,
}

for _, input := range validInput {
allErrs := validateMatchExpect(input, field.NewPath("expect"))
if len(allErrs) > 0 {
t.Errorf("validateMatchExpect(%q) returned errors %v for valid input", input, allErrs)
}
}
for _, input := range invalidInput {
allErrs := validateMatchExpect(input, field.NewPath("expect"))
if len(allErrs) == 0 {
Expand All @@ -940,8 +982,11 @@ func TestValidateTsTLS(t *testing.T) {
t.Errorf("validateTLS() returned errors %v for valid input %v", allErrs, tls)
}
}
}

tests := []struct {
func TestValidateTsTLS_FailsOnInvalidInput(t *testing.T) {
t.Parallel()
invalidTLSes := []struct {
tls *v1alpha1.TLS
isTLSPassthrough bool
}{
Expand Down Expand Up @@ -971,7 +1016,7 @@ func TestValidateTsTLS(t *testing.T) {
},
}

for _, test := range tests {
for _, test := range invalidTLSes {
allErrs := validateTLS(test.tls, test.isTLSPassthrough, field.NewPath("tls"))
if len(allErrs) == 0 {
t.Errorf("validateTLS() returned no errors for invalid input %v", test)
Expand Down