Adds CustomHTTPErrors ingress annotation and test
Adds per-server/location error-catch functionality to nginx template Adds documentation Reduces template duplication with helper function for CUSTOM_ERRORS data Updates documentation Adds e2e test for customerrors Removes AllCustomHTTPErrors, replaces with template function with deduplication and adds e2e test of deduplication Fixes copy-paste error in test, adds additional test cases Reverts noop change in controller.go (unused now)
This commit is contained in:
parent
1f76acfa6a
commit
0ebf0354cb
9 changed files with 294 additions and 11 deletions
|
|
@ -43,6 +43,7 @@ var (
|
|||
annotationAffinityCookieName = parser.GetAnnotationWithPrefix("session-cookie-name")
|
||||
annotationAffinityCookieHash = parser.GetAnnotationWithPrefix("session-cookie-hash")
|
||||
annotationUpstreamHashBy = parser.GetAnnotationWithPrefix("upstream-hash-by")
|
||||
annotationCustomHTTPErrors = parser.GetAnnotationWithPrefix("custom-http-errors")
|
||||
)
|
||||
|
||||
type mockCfg struct {
|
||||
|
|
@ -270,6 +271,41 @@ func TestCors(t *testing.T) {
|
|||
|
||||
}
|
||||
}
|
||||
func TestCustomHTTPErrors(t *testing.T) {
|
||||
ec := NewAnnotationExtractor(mockCfg{})
|
||||
ing := buildIngress()
|
||||
|
||||
fooAnns := []struct {
|
||||
annotations map[string]string
|
||||
er []int
|
||||
}{
|
||||
{map[string]string{annotationCustomHTTPErrors: "404,415"}, []int{404, 415}},
|
||||
{map[string]string{annotationCustomHTTPErrors: "404"}, []int{404}},
|
||||
{map[string]string{annotationCustomHTTPErrors: ""}, []int{}},
|
||||
{map[string]string{annotationCustomHTTPErrors + "_no": "404"}, []int{}},
|
||||
{map[string]string{}, []int{}},
|
||||
{nil, []int{}},
|
||||
}
|
||||
|
||||
for _, foo := range fooAnns {
|
||||
ing.SetAnnotations(foo.annotations)
|
||||
r := ec.Extract(ing).CustomHTTPErrors
|
||||
|
||||
// Check that expected codes were created
|
||||
for i := range foo.er {
|
||||
if r[i] != foo.er[i] {
|
||||
t.Errorf("Returned %v but expected %v", r, foo.er)
|
||||
}
|
||||
}
|
||||
|
||||
// Check that no unexpected codes were also created
|
||||
for i := range r {
|
||||
if r[i] != foo.er[i] {
|
||||
t.Errorf("Returned %v but expected %v", r, foo.er)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestMergeLocationAnnotations(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue