@@ -163,15 +163,38 @@ func TestAnnotations(t *testing.T) {
163
163
if u .ValidationDepth != 2 {
164
164
t .Errorf ("expected %v but got %v" , 2 , u .ValidationDepth )
165
165
}
166
- if u .ErrorPage != "ok.com/error" {
167
- t .Errorf ("expected %v but got %v" , "ok.com/error" , u .ErrorPage )
168
- }
169
166
if u .PassCertToUpstream != true {
170
167
t .Errorf ("expected %v but got %v" , true , u .PassCertToUpstream )
171
168
}
172
169
if u .MatchCN != "CN=(hello-app|ok|goodbye)" {
173
170
t .Errorf ("expected %v but got %v" , "CN=(hello-app|ok|goodbye)" , u .MatchCN )
174
171
}
172
+
173
+ // Cleaner: table-driven test for error page values
174
+ for _ , tc := range []struct {
175
+ name string
176
+ errorPage string
177
+ want string
178
+ }{
179
+ {"named redirect" , "@401" , "@401" },
180
+ {"url redirect" , "ok.com/error" , "ok.com/error" },
181
+ } {
182
+ t .Run (tc .name , func (t * testing.T ) {
183
+ data [parser .GetAnnotationWithPrefix (annotationAuthTLSErrorPage )] = tc .errorPage
184
+ ing .SetAnnotations (data )
185
+ i , err := NewParser (fakeSecret ).Parse (ing )
186
+ if err != nil {
187
+ t .Errorf ("Unexpected error with ingress: %v" , err )
188
+ }
189
+ u , ok := i .(* Config )
190
+ if ! ok {
191
+ t .Errorf ("expected *Config but got %v" , u )
192
+ }
193
+ if u .ErrorPage != tc .want {
194
+ t .Errorf ("expected %v but got %v" , tc .want , u .ErrorPage )
195
+ }
196
+ })
197
+ }
175
198
}
176
199
177
200
func TestInvalidAnnotations (t * testing.T ) {
0 commit comments