@@ -27,6 +27,11 @@ import (
2727 "k8s.io/ingress-nginx/internal/ingress/resolver"
2828)
2929
30+ const (
31+ DefaultHttpErrorsString = "400,404,500,502"
32+ DefaultHttpErrorsSlice = []int {400 , 404 , 500 , 502 }
33+ )
34+
3035func buildIngress () * networking.Ingress {
3136 return & networking.Ingress {
3237 ObjectMeta : meta_v1.ObjectMeta {
@@ -50,7 +55,7 @@ func TestParseCodes(t *testing.T) {
5055 ing := buildIngress ()
5156
5257 data := map [string ]string {}
53- data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = "400,404,500,502"
58+ data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = DefaultHttpErrorsString
5459 ing .SetAnnotations (data )
5560
5661 i , err := NewParser (& resolver.Mock {}).Parse (ing )
@@ -62,7 +67,7 @@ func TestParseCodes(t *testing.T) {
6267 t .Errorf ("expected a []int type" )
6368 }
6469
65- expected := [] int { 400 , 404 , 500 , 502 }
70+ expected := DefaultHttpErrorsSlice
6671 if ! reflect .DeepEqual (expected , val ) {
6772 t .Errorf ("expected %v but got %v" , expected , val )
6873 }
@@ -73,7 +78,7 @@ func TestEnabledSwitch(t *testing.T) {
7378
7479 data := map [string ]string {}
7580 data [parser .GetAnnotationWithPrefix ("enable-custom-http-errors" )] = "true"
76- data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = "400,404,500,502"
81+ data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = DefaultHttpErrorsString
7782 ing .SetAnnotations (data )
7883
7984 i , err := NewParser (& resolver.Mock {}).Parse (ing )
@@ -85,7 +90,7 @@ func TestEnabledSwitch(t *testing.T) {
8590 t .Errorf ("expected a []int type" )
8691 }
8792
88- expected := [] int { 400 , 404 , 500 , 502 }
93+ expected := DefaultHttpErrorsSlice
8994 if ! reflect .DeepEqual (expected , val ) {
9095 t .Errorf ("expected %v but got %v" , expected , val )
9196 }
@@ -96,7 +101,7 @@ func TestDisabledSwitch(t *testing.T) {
96101
97102 data := map [string ]string {}
98103 data [parser .GetAnnotationWithPrefix ("enable-custom-http-errors" )] = "false"
99- data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = "400,404,500,502"
104+ data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = DefaultHttpErrorsString
100105 ing .SetAnnotations (data )
101106
102107 i , err := NewParser (& resolver.Mock {}).Parse (ing )
@@ -119,7 +124,7 @@ func TestEnabledByDefault(t *testing.T) {
119124
120125 data := map [string ]string {}
121126 data [parser .GetAnnotationWithPrefix ("enable-custom-http-errors" )] = "fakebool"
122- data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = "400,404,500,502"
127+ data [parser .GetAnnotationWithPrefix ("custom-http-errors" )] = DefaultHttpErrorsString
123128 ing .SetAnnotations (data )
124129
125130 i , err := NewParser (& resolver.Mock {}).Parse (ing )
@@ -131,7 +136,7 @@ func TestEnabledByDefault(t *testing.T) {
131136 t .Errorf ("expected a []int type" )
132137 }
133138
134- expected := [] int { 400 , 404 , 500 , 502 }
139+ expected := DefaultHttpErrorsSlice
135140 if ! reflect .DeepEqual (expected , val ) {
136141 t .Errorf ("expected %v but got %v" , expected , val )
137142 }
0 commit comments