Skip to content

Commit 7de5a59

Browse files
committed
wip
1 parent ffebc09 commit 7de5a59

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

internal/ingress/annotations/authtls/main_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,38 @@ func TestAnnotations(t *testing.T) {
163163
if u.ValidationDepth != 2 {
164164
t.Errorf("expected %v but got %v", 2, u.ValidationDepth)
165165
}
166-
if u.ErrorPage != "ok.com/error" {
167-
t.Errorf("expected %v but got %v", "ok.com/error", u.ErrorPage)
168-
}
169166
if u.PassCertToUpstream != true {
170167
t.Errorf("expected %v but got %v", true, u.PassCertToUpstream)
171168
}
172169
if u.MatchCN != "CN=(hello-app|ok|goodbye)" {
173170
t.Errorf("expected %v but got %v", "CN=(hello-app|ok|goodbye)", u.MatchCN)
174171
}
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+
}
175198
}
176199

177200
func TestInvalidAnnotations(t *testing.T) {

0 commit comments

Comments
 (0)