@@ -14,6 +14,7 @@ func createTransportServerValidator() *TransportServerValidator {
14
14
15
15
func TestValidateTransportServer (t * testing.T ) {
16
16
t .Parallel ()
17
+
17
18
ts := v1alpha1.TransportServer {
18
19
Spec : v1alpha1.TransportServerSpec {
19
20
Listener : v1alpha1.TransportServerListener {
@@ -41,7 +42,7 @@ func TestValidateTransportServer(t *testing.T) {
41
42
}
42
43
}
43
44
44
- func TestValidateTransportServerFails (t * testing.T ) {
45
+ func TestValidateTransportServer_FailsOnInvalidInput (t * testing.T ) {
45
46
t .Parallel ()
46
47
ts := v1alpha1.TransportServer {
47
48
Spec : v1alpha1.TransportServerSpec {
@@ -69,6 +70,7 @@ func TestValidateTransportServerFails(t *testing.T) {
69
70
}
70
71
71
72
func TestValidateTransportServerUpstreams (t * testing.T ) {
73
+ t .Parallel ()
72
74
tests := []struct {
73
75
upstreams []v1alpha1.Upstream
74
76
expectedUpstreamNames sets.Set [string ]
@@ -103,15 +105,16 @@ func TestValidateTransportServerUpstreams(t *testing.T) {
103
105
for _ , test := range tests {
104
106
allErrs , resultUpstreamNames := validateTransportServerUpstreams (test .upstreams , field .NewPath ("upstreams" ), true )
105
107
if len (allErrs ) > 0 {
106
- t .Errorf ("validateTransportServerUpstreams() returned errors %v for valid input for the case of %s" , allErrs , test .msg )
108
+ t .Fatalf ("validateTransportServerUpstreams() returned errors %v for valid input for the case of %s" , allErrs , test .msg )
107
109
}
108
110
if ! resultUpstreamNames .Equal (test .expectedUpstreamNames ) {
109
111
t .Errorf ("validateTransportServerUpstreams() returned %v expected %v for the case of %s" , resultUpstreamNames , test .expectedUpstreamNames , test .msg )
110
112
}
111
113
}
112
114
}
113
115
114
- func TestValidateTransportServerUpstreamsFails (t * testing.T ) {
116
+ func TestValidateTransportServerUpstreams_FailsOnInvalidInput (t * testing.T ) {
117
+ t .Parallel ()
115
118
tests := []struct {
116
119
upstreams []v1alpha1.Upstream
117
120
expectedUpstreamNames sets.Set [string ]
@@ -177,7 +180,7 @@ func TestValidateTransportServerUpstreamsFails(t *testing.T) {
177
180
for _ , test := range tests {
178
181
allErrs , resultUpstreamNames := validateTransportServerUpstreams (test .upstreams , field .NewPath ("upstreams" ), true )
179
182
if len (allErrs ) == 0 {
180
- t .Errorf ("validateTransportServerUpstreams() returned no errors for the case of %s" , test .msg )
183
+ t .Fatalf ("validateTransportServerUpstreams() returned no errors for the case of %s" , test .msg )
181
184
}
182
185
if ! resultUpstreamNames .Equal (test .expectedUpstreamNames ) {
183
186
t .Errorf ("validateTransportServerUpstreams() returned %v expected %v for the case of %s" , resultUpstreamNames , test .expectedUpstreamNames , test .msg )
@@ -186,6 +189,7 @@ func TestValidateTransportServerUpstreamsFails(t *testing.T) {
186
189
}
187
190
188
191
func TestValidateTransportServerHost (t * testing.T ) {
192
+ t .Parallel ()
189
193
tests := []struct {
190
194
host string
191
195
isTLSPassthroughListener bool
@@ -209,6 +213,8 @@ func TestValidateTransportServerHost(t *testing.T) {
209
213
}
210
214
211
215
func TestValidateTransportServerLoadBalancingMethod (t * testing.T ) {
216
+ t .Parallel ()
217
+
212
218
tests := []struct {
213
219
method string
214
220
isPlus bool
@@ -314,7 +320,7 @@ func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
314
320
for _ , test := range tests {
315
321
allErrs := validateLoadBalancingMethod (test .method , field .NewPath ("method" ), test .isPlus )
316
322
if ! test .hasError && len (allErrs ) > 0 {
317
- t .Errorf ("validateLoadBalancingMethod(%q, %v) returned errors %v for valid input" , test .method , test .isPlus , allErrs )
323
+ t .Fatalf ("validateLoadBalancingMethod(%q, %v) returned errors %v for valid input" , test .method , test .isPlus , allErrs )
318
324
}
319
325
if test .hasError && len (allErrs ) < 1 {
320
326
t .Errorf ("validateLoadBalancingMethod(%q, %v) failed to return an error for invalid input" , test .method , test .isPlus )
@@ -323,6 +329,7 @@ func TestValidateTransportServerLoadBalancingMethod(t *testing.T) {
323
329
}
324
330
325
331
func TestValidateTransportServerSnippet (t * testing.T ) {
332
+ t .Parallel ()
326
333
tests := []struct {
327
334
snippet string
328
335
isSnippetsEnabled bool
@@ -359,7 +366,8 @@ func TestValidateTransportServerSnippet(t *testing.T) {
359
366
}
360
367
}
361
368
362
- func TestValidateTransportServerHostFails (t * testing.T ) {
369
+ func TestValidateTransportServerHost_FailsOnInvalidInput (t * testing.T ) {
370
+ t .Parallel ()
363
371
tests := []struct {
364
372
host string
365
373
isTLSPassthroughListener bool
@@ -383,6 +391,7 @@ func TestValidateTransportServerHostFails(t *testing.T) {
383
391
}
384
392
385
393
func TestValidateTransportListener (t * testing.T ) {
394
+ t .Parallel ()
386
395
tests := []struct {
387
396
listener * v1alpha1.TransportServerListener
388
397
tlsPassthrough bool
@@ -422,7 +431,8 @@ func TestValidateTransportListener(t *testing.T) {
422
431
}
423
432
}
424
433
425
- func TestValidateTransportListenerFails (t * testing.T ) {
434
+ func TestValidateTransportListener_FailsOnInvalidInput (t * testing.T ) {
435
+ t .Parallel ()
426
436
tests := []struct {
427
437
listener * v1alpha1.TransportServerListener
428
438
tlsPassthrough bool
@@ -477,6 +487,7 @@ func TestValidateTransportListenerFails(t *testing.T) {
477
487
}
478
488
479
489
func TestValidateIsPotentialTLSPassthroughListener (t * testing.T ) {
490
+ t .Parallel ()
480
491
tests := []struct {
481
492
listener * v1alpha1.TransportServerListener
482
493
expected bool
@@ -513,6 +524,7 @@ func TestValidateIsPotentialTLSPassthroughListener(t *testing.T) {
513
524
}
514
525
515
526
func TestValidateListenerProtocol (t * testing.T ) {
527
+ t .Parallel ()
516
528
validProtocols := []string {
517
529
"TCP" ,
518
530
"UDP" ,
@@ -524,7 +536,10 @@ func TestValidateListenerProtocol(t *testing.T) {
524
536
t .Errorf ("validateListenerProtocol(%q) returned errors %v for valid input" , p , allErrs )
525
537
}
526
538
}
539
+ }
527
540
541
+ func TestValidateListenerProtocol_FailsOnInvalidInput (t * testing.T ) {
542
+ t .Parallel ()
528
543
invalidProtocols := []string {
529
544
"" ,
530
545
"HTTP" ,
@@ -541,6 +556,7 @@ func TestValidateListenerProtocol(t *testing.T) {
541
556
}
542
557
543
558
func TestValidateTSUpstreamHealthChecks (t * testing.T ) {
559
+ t .Parallel ()
544
560
tests := []struct {
545
561
healthCheck * v1alpha1.HealthCheck
546
562
msg string
@@ -574,7 +590,8 @@ func TestValidateTSUpstreamHealthChecks(t *testing.T) {
574
590
}
575
591
}
576
592
577
- func TestValidateTSUpstreamHealthChecksFails (t * testing.T ) {
593
+ func TestValidateTSUpstreamHealthChecks_FailsOnInvalidInput (t * testing.T ) {
594
+ t .Parallel ()
578
595
tests := []struct {
579
596
healthCheck * v1alpha1.HealthCheck
580
597
msg string
@@ -662,6 +679,7 @@ func TestValidateTSUpstreamHealthChecksFails(t *testing.T) {
662
679
}
663
680
664
681
func TestValidateUpstreamParameters (t * testing.T ) {
682
+ t .Parallel ()
665
683
tests := []struct {
666
684
parameters * v1alpha1.UpstreamParameters
667
685
msg string
@@ -685,6 +703,7 @@ func TestValidateUpstreamParameters(t *testing.T) {
685
703
}
686
704
687
705
func TestValidateSessionParameters (t * testing.T ) {
706
+ t .Parallel ()
688
707
tests := []struct {
689
708
parameters * v1alpha1.SessionParameters
690
709
msg string
@@ -713,7 +732,8 @@ func TestValidateSessionParameters(t *testing.T) {
713
732
}
714
733
}
715
734
716
- func TestValidateSessionParametersFails (t * testing.T ) {
735
+ func TestValidateSessionParameters_FailsOnInvalidInput (t * testing.T ) {
736
+ t .Parallel ()
717
737
tests := []struct {
718
738
parameters * v1alpha1.SessionParameters
719
739
msg string
@@ -735,6 +755,7 @@ func TestValidateSessionParametersFails(t *testing.T) {
735
755
}
736
756
737
757
func TestValidateUDPUpstreamParameter (t * testing.T ) {
758
+ t .Parallel ()
738
759
validInput := []struct {
739
760
parameter * int
740
761
protocol string
@@ -765,7 +786,8 @@ func TestValidateUDPUpstreamParameter(t *testing.T) {
765
786
}
766
787
}
767
788
768
- func TestValidateUDPUpstreamParameterFails (t * testing.T ) {
789
+ func TestValidateUDPUpstreamParameter_FailsOnInvalidInput (t * testing.T ) {
790
+ t .Parallel ()
769
791
invalidInput := []struct {
770
792
parameter * int
771
793
protocol string
@@ -789,6 +811,7 @@ func TestValidateUDPUpstreamParameterFails(t *testing.T) {
789
811
}
790
812
791
813
func TestValidateTransportServerAction (t * testing.T ) {
814
+ t .Parallel ()
792
815
upstreamNames := map [string ]sets.Empty {
793
816
"test" : {},
794
817
}
@@ -803,7 +826,8 @@ func TestValidateTransportServerAction(t *testing.T) {
803
826
}
804
827
}
805
828
806
- func TestValidateTransportServerActionFails (t * testing.T ) {
829
+ func TestValidateTransportServerAction_FailsOnInvalidInput (t * testing.T ) {
830
+ t .Parallel ()
807
831
upstreamNames := map [string ]sets.Empty {}
808
832
809
833
tests := []struct {
@@ -833,23 +857,29 @@ func TestValidateTransportServerActionFails(t *testing.T) {
833
857
}
834
858
835
859
func TestValidateMatchSend (t * testing.T ) {
860
+ t .Parallel ()
836
861
validInput := []string {
837
862
"" ,
838
863
"abc" ,
839
864
"hello${world}" ,
840
865
`hello\x00` ,
841
866
}
842
- invalidInput := []string {
843
- `hello"world` ,
844
- `\x1x` ,
845
- }
846
867
847
868
for _ , send := range validInput {
848
869
allErrs := validateMatchSend (send , field .NewPath ("send" ))
849
870
if len (allErrs ) > 0 {
850
871
t .Errorf ("validateMatchSend(%q) returned errors %v for valid input" , send , allErrs )
851
872
}
852
873
}
874
+ }
875
+
876
+ func TestValidateMatchSend_FailsOnInvalidInput (t * testing.T ) {
877
+ t .Parallel ()
878
+ invalidInput := []string {
879
+ `hello"world` ,
880
+ `\x1x` ,
881
+ }
882
+
853
883
for _ , send := range invalidInput {
854
884
allErrs := validateMatchSend (send , field .NewPath ("send" ))
855
885
if len (allErrs ) == 0 {
@@ -859,6 +889,7 @@ func TestValidateMatchSend(t *testing.T) {
859
889
}
860
890
861
891
func TestValidateHexString (t * testing.T ) {
892
+ t .Parallel ()
862
893
validInput := []string {
863
894
"" ,
864
895
"abc" ,
@@ -868,6 +899,17 @@ func TestValidateHexString(t *testing.T) {
868
899
`\xff` ,
869
900
`\xaaFFabc\x12` ,
870
901
}
902
+
903
+ for _ , s := range validInput {
904
+ err := validateHexString (s )
905
+ if err != nil {
906
+ t .Errorf ("validateHexString(%q) returned error %v for valid input" , s , err )
907
+ }
908
+ }
909
+ }
910
+
911
+ func TestValidateHexString_FailsOnInvalidInput (t * testing.T ) {
912
+ t .Parallel ()
871
913
invalidInput := []string {
872
914
`\x` ,
873
915
`\x1` ,
@@ -876,12 +918,6 @@ func TestValidateHexString(t *testing.T) {
876
918
`\xaaFFabc\xx12` , // \xx1 is invalid
877
919
}
878
920
879
- for _ , s := range validInput {
880
- err := validateHexString (s )
881
- if err != nil {
882
- t .Errorf ("validateHexString(%q) returned error %v for valid input" , s , err )
883
- }
884
- }
885
921
for _ , s := range invalidInput {
886
922
err := validateHexString (s )
887
923
if err == nil {
@@ -891,6 +927,7 @@ func TestValidateHexString(t *testing.T) {
891
927
}
892
928
893
929
func TestValidateMatchExpect (t * testing.T ) {
930
+ t .Parallel ()
894
931
validInput := []string {
895
932
`` ,
896
933
`abc` ,
@@ -900,6 +937,17 @@ func TestValidateMatchExpect(t *testing.T) {
900
937
`~` ,
901
938
`~*` ,
902
939
}
940
+
941
+ for _ , input := range validInput {
942
+ allErrs := validateMatchExpect (input , field .NewPath ("expect" ))
943
+ if len (allErrs ) > 0 {
944
+ t .Errorf ("validateMatchExpect(%q) returned errors %v for valid input" , input , allErrs )
945
+ }
946
+ }
947
+ }
948
+
949
+ func TestValidateMatchExpect_FailsOnInvalidInput (t * testing.T ) {
950
+ t .Parallel ()
903
951
invalidInput := []string {
904
952
`hello"world` ,
905
953
`~hello"world` ,
@@ -911,12 +959,6 @@ func TestValidateMatchExpect(t *testing.T) {
911
959
`~{1}` ,
912
960
}
913
961
914
- for _ , input := range validInput {
915
- allErrs := validateMatchExpect (input , field .NewPath ("expect" ))
916
- if len (allErrs ) > 0 {
917
- t .Errorf ("validateMatchExpect(%q) returned errors %v for valid input" , input , allErrs )
918
- }
919
- }
920
962
for _ , input := range invalidInput {
921
963
allErrs := validateMatchExpect (input , field .NewPath ("expect" ))
922
964
if len (allErrs ) == 0 {
@@ -940,8 +982,11 @@ func TestValidateTsTLS(t *testing.T) {
940
982
t .Errorf ("validateTLS() returned errors %v for valid input %v" , allErrs , tls )
941
983
}
942
984
}
985
+ }
943
986
944
- tests := []struct {
987
+ func TestValidateTsTLS_FailsOnInvalidInput (t * testing.T ) {
988
+ t .Parallel ()
989
+ invalidTLSes := []struct {
945
990
tls * v1alpha1.TLS
946
991
isTLSPassthrough bool
947
992
}{
@@ -971,7 +1016,7 @@ func TestValidateTsTLS(t *testing.T) {
971
1016
},
972
1017
}
973
1018
974
- for _ , test := range tests {
1019
+ for _ , test := range invalidTLSes {
975
1020
allErrs := validateTLS (test .tls , test .isTLSPassthrough , field .NewPath ("tls" ))
976
1021
if len (allErrs ) == 0 {
977
1022
t .Errorf ("validateTLS() returned no errors for invalid input %v" , test )
0 commit comments