@@ -2544,7 +2544,7 @@ func TestValidateNginxIngressAnnotations(t *testing.T) {
2544
2544
func TestValidateIngressSpec (t * testing.T ) {
2545
2545
tests := []struct {
2546
2546
spec * networking.IngressSpec
2547
- expectedErrors []string
2547
+ expectedErrors []field. ErrorType
2548
2548
msg string
2549
2549
}{
2550
2550
{
@@ -2570,6 +2570,56 @@ func TestValidateIngressSpec(t *testing.T) {
2570
2570
expectedErrors : nil ,
2571
2571
msg : "valid input" ,
2572
2572
},
2573
+ {
2574
+ spec : & networking.IngressSpec {
2575
+ Rules : []networking.IngressRule {
2576
+ {
2577
+ Host : "foo.example.com" ,
2578
+ IngressRuleValue : networking.IngressRuleValue {
2579
+ HTTP : & networking.HTTPIngressRuleValue {
2580
+ Paths : []networking.HTTPIngressPath {
2581
+ {
2582
+ Path : `/tea\{custom_value}` ,
2583
+ Backend : networking.IngressBackend {
2584
+ Service : & networking.IngressServiceBackend {},
2585
+ },
2586
+ },
2587
+ },
2588
+ },
2589
+ },
2590
+ },
2591
+ },
2592
+ },
2593
+ expectedErrors : []field.ErrorType {
2594
+ field .ErrorTypeInvalid ,
2595
+ },
2596
+ msg : "test invalid characters in path" ,
2597
+ },
2598
+ {
2599
+ spec : & networking.IngressSpec {
2600
+ Rules : []networking.IngressRule {
2601
+ {
2602
+ Host : "foo.example.com" ,
2603
+ IngressRuleValue : networking.IngressRuleValue {
2604
+ HTTP : & networking.HTTPIngressRuleValue {
2605
+ Paths : []networking.HTTPIngressPath {
2606
+ {
2607
+ Path : "" ,
2608
+ Backend : networking.IngressBackend {
2609
+ Service : & networking.IngressServiceBackend {},
2610
+ },
2611
+ },
2612
+ },
2613
+ },
2614
+ },
2615
+ },
2616
+ },
2617
+ },
2618
+ expectedErrors : []field.ErrorType {
2619
+ field .ErrorTypeRequired ,
2620
+ },
2621
+ msg : "test empty in path" ,
2622
+ },
2573
2623
{
2574
2624
spec : & networking.IngressSpec {
2575
2625
DefaultBackend : & networking.IngressBackend {
@@ -2588,8 +2638,8 @@ func TestValidateIngressSpec(t *testing.T) {
2588
2638
spec : & networking.IngressSpec {
2589
2639
Rules : []networking.IngressRule {},
2590
2640
},
2591
- expectedErrors : []string {
2592
- "spec.rules: Required value" ,
2641
+ expectedErrors : []field. ErrorType {
2642
+ field . ErrorTypeRequired ,
2593
2643
},
2594
2644
msg : "zero rules" ,
2595
2645
},
@@ -2601,8 +2651,8 @@ func TestValidateIngressSpec(t *testing.T) {
2601
2651
},
2602
2652
},
2603
2653
},
2604
- expectedErrors : []string {
2605
- "spec.rules[0].host: Required value" ,
2654
+ expectedErrors : []field. ErrorType {
2655
+ field . ErrorTypeRequired ,
2606
2656
},
2607
2657
msg : "empty host" ,
2608
2658
},
@@ -2617,8 +2667,8 @@ func TestValidateIngressSpec(t *testing.T) {
2617
2667
},
2618
2668
},
2619
2669
},
2620
- expectedErrors : []string {
2621
- `spec.rules[1].host: Duplicate value: "foo.example.com"` ,
2670
+ expectedErrors : []field. ErrorType {
2671
+ field . ErrorTypeDuplicate ,
2622
2672
},
2623
2673
msg : "duplicated host" ,
2624
2674
},
@@ -2633,8 +2683,8 @@ func TestValidateIngressSpec(t *testing.T) {
2633
2683
},
2634
2684
},
2635
2685
},
2636
- expectedErrors : []string {
2637
- "spec.defaultBackend.resource: Forbidden: resource backends are not supported" ,
2686
+ expectedErrors : []field. ErrorType {
2687
+ field . ErrorTypeForbidden ,
2638
2688
},<
6968
/div>
2639
2689
msg : "invalid default backend" ,
2640
2690
},
@@ -2658,16 +2708,16 @@ func TestValidateIngressSpec(t *testing.T) {
2658
2708
},
2659
2709
},
2660
2710
},
2661
- expectedErrors : []string {
2662
- "spec.rules[0].http.path[0].backend.resource: Forbidden: resource backends are not supported" ,
2711
+ expectedErrors : []field. ErrorType {
2712
+ field . ErrorTypeForbidden ,
2663
2713
},
2664
2714
msg : "invalid backend" ,
2665
2715
},
2666
2716
}
2667
2717
2668
2718
for _ , test := range tests {
2669
2719
allErrs := validateIngressSpec (test .spec , field .NewPath ("spec" ))
2670
- assertion := assertErrors ( "validateIngressSpec()" , test .msg , allErrs , test .expectedErrors )
2720
+ assertion := assertErrorTypes ( test .msg , allErrs , test .expectedErrors )
2671
2721
if assertion != "" {
2672
2722
t .Error (assertion )
2673
2723
}
@@ -2843,6 +2893,14 @@ func TestValidateMinionSpec(t *testing.T) {
2843
2893
}
2844
2894
}
2845
2895
2896
+ func assertErrorTypes (msg string , allErrs field.ErrorList , expectedErrors []field.ErrorType ) string {
2897
+ returnedErrors := errorListToTypes (allErrs )
2898
+ if ! reflect .DeepEqual (returnedErrors , expectedErrors ) {
2899
+ return fmt .Sprintf ("%s returned %s but expected %s" , msg , returnedErrors , expectedErrors )
2900
+ }
2901
+ return ""
2902
+ }
2903
+
2846
2904
func assertErrors (funcName string , msg string , allErrs field.ErrorList , expectedErrors []string ) string {
2847
2905
errors := errorListToStrings (allErrs )
2848
2906
if ! reflect .DeepEqual (errors , expectedErrors ) {
@@ -2865,6 +2923,16 @@ func errorListToStrings(list field.ErrorList) []string {
2865
2923
return result
2866
2924
}
2867
2925
2926
+ func errorListToTypes (list field.ErrorList ) []field.ErrorType {
2927
+ var result []field.ErrorType
2928
+
2929
+ for _ , e := range list {
2930
+ result = append (result , e .Type )
2931
+ }
5ECB
td>
2932
+
2933
+ return result
2934
+ }
2935
+
2868
2936
func TestGetSpecServices (t * testing.T ) {
2869
2937
tests := []struct {
2870
2938
spec networking.IngressSpec
0 commit comments