Skip to content

Commit

Permalink
Matched ErrorPageReturn with ActionReturn, updated tests and generate…
Browse files Browse the repository at this point in the history
…d config
  • Loading branch information
andrew-s committed Apr 27, 2024
1 parent 4598c26 commit 9113565
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 41 deletions.
80 changes: 80 additions & 0 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1149,6 +1159,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1256,6 +1276,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1362,6 +1392,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1772,6 +1812,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -1900,6 +1950,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -2007,6 +2067,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down Expand Up @@ -2113,6 +2183,16 @@ spec:
type: string
code:
type: integer
headers:
items:
description: Header defines an HTTP Header.
properties:
name:
type: string
value:
type: string
type: object
type: array
type:
type: string
type: object
Expand Down
44 changes: 22 additions & 22 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9100,11 +9100,11 @@ func TestGenerateSplits(t *testing.T) {
Code: 200,
Type: "application/json",
Body: `{\"message\": \"ok\"}`,
},
Headers: []conf_v1.Header{
{
Name: "Set-Cookie",
Value: "cookie1=value",
Headers: []conf_v1.Header{
{
Name: "Set-Cookie",
Value: "cookie1=value",
},
},
},
},
Expand Down Expand Up @@ -11125,11 +11125,11 @@ func TestGenerateMatchesConfig(t *testing.T) {
Code: 200,
Type: "application/json",
Body: `{\"message\": \"ok\"}`,
},
Headers: []conf_v1.Header{
{
Name: "Set-Cookie",
Value: "cookie1=value",
Headers: []conf_v1.Header{
{
Name: "Set-Cookie",
Value: "cookie1=value",
},
},
},
},
Expand Down Expand Up @@ -11542,11 +11542,11 @@ func TestGenerateMatchesConfigWithMultipleSplits(t *testing.T) {
Code: 200,
Type: "application/json",
Body: `{\"message\": \"ok\"}`,
},
Headers: []conf_v1.Header{
{
Name: "Set-Cookie",
Value: "cookie1=value",
Headers: []conf_v1.Header{
{
Name: "Set-Cookie",
Value: "cookie1=value",
},
},
},
},
Expand Down Expand Up @@ -12943,9 +12943,9 @@ func TestGenerateErrorPages(t *testing.T) {
Codes: []int{404, 405, 500, 502},
Return: &conf_v1.ErrorPageReturn{
ActionReturn: conf_v1.ActionReturn{
Code: 200,
Code: 200,
Headers: nil,
},
Headers: nil,
},
Redirect: nil,
},
Expand Down Expand Up @@ -13024,11 +13024,11 @@ func TestGenerateErrorPageLocations(t *testing.T) {
Code: 200,
Type: "application/json",
Body: "Hello World",
},
Headers: []conf_v1.Header{
{
Name: "HeaderName",
Value: "HeaderValue",
Headers: []conf_v1.Header{
{
Name: "HeaderName",
Value: "HeaderValue",
},
},
},
},
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/configuration/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ type ErrorPage struct {
// ErrorPageReturn defines a return for an ErrorPage.
type ErrorPageReturn struct {
ActionReturn `json:",inline"`
Headers []Header `json:"headers"`
}

// ErrorPageRedirect defines a redirect for an ErrorPage.
Expand Down
36 changes: 18 additions & 18 deletions pkg/apis/configuration/validation/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4323,32 +4323,32 @@ func TestValidateErrorPageReturn(t *testing.T) {
tests := []v1.ErrorPageReturn{
{
ActionReturn: v1.ActionReturn{
Code: 200,
Type: "",
Body: "Could not process request, try again",
Code: 200,
Type: "",
Body: "Could not process request, try again",
Headers: nil,
},
Headers: nil,
},
{
ActionReturn: v1.ActionReturn{
Code: 0,
Type: "",
Body: "Could not process request, try again. Upstream status ${upstream_status}",
},
Headers: []v1.Header{
{
Name: "Set-Cookie",
Value: "mycookie=true",
Headers: []v1.Header{
{
Name: "Set-Cookie",
Value: "mycookie=true",
},
},
},
},
{
ActionReturn: v1.ActionReturn{
Code: 200,
Type: "application/json",
Body: `{\"message\": \"Could not process request, try again\", \"upstream_status\": \"${upstream_status}\"}`,
Code: 200,
Type: "application/json",
Body: `{\"message\": \"Could not process request, try again\", \"upstream_status\": \"${upstream_status}\"}`,
Headers: nil,
},
Headers: nil,
},
}

Expand Down Expand Up @@ -4406,11 +4406,11 @@ func TestValidateErrorPageReturnFails(t *testing.T) {
Code: 200,
Type: "application/json",
Body: `{\"message\": \"Could not process request, try again\", \"status\": \"${status}\"}`,
},
Headers: []v1.Header{
{
Name: "Set-Cookie$_%^$ -",
Value: "mycookie=true",
Headers: []v1.Header{
{
Name: "Set-Cookie$_%^$ -",
Value: "mycookie=true",
},
},
},
},
Expand Down

0 comments on commit 9113565

Please sign in to comment.