Skip to content

Commit

Permalink
address nit comments and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Apr 30, 2024
1 parent 3d3670a commit e4f6129
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
68 changes: 68 additions & 0 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1975,3 +1975,71 @@ func TestConvertBackendTLSFromGroup(t *testing.T) {
})
}
}

func TestGenerateResponseHeaders(t *testing.T) {
tests := []struct {
filters *dataplane.HTTPFilters
msg string
expectedHeaders http.ResponseHeaders
}{
{
msg: "no filter set",
filters: &dataplane.HTTPFilters{
RequestHeaderModifiers: &dataplane.HTTPHeaderFilter{},
},
expectedHeaders: http.ResponseHeaders{},
},
{
msg: "set filters correctly",
filters: &dataplane.HTTPFilters{
ResponseHeaderModifiers: &dataplane.HTTPHeaderFilter{
Add: []dataplane.HTTPHeader{
{
Name: "Accept-Encoding",
Value: "gzip",
},
{
Name: "Authorization",
Value: "my-auth",
},
},
Set: []dataplane.HTTPHeader{
{
Name: "Accept-Encoding",
Value: "my-new-overwritten-value",
},
},
Remove: []string{"Authorization"},
},
},
expectedHeaders: http.ResponseHeaders{
Add: []http.Header{
{
Name: "Accept-Encoding",
Value: "gzip",
},
{
Name: "Authorization",
Value: "my-auth",
},
},
Set: []http.Header{
{
Name: "Accept-Encoding",
Value: "my-new-overwritten-value",
},
},
Remove: []string{"Authorization"},
},
},
}

for _, tc := range tests {
t.Run(tc.msg, func(t *testing.T) {
g := NewWithT(t)

headers := generateResponseHeaders(tc.filters)
g.Expect(headers).To(Equal(tc.expectedHeaders))
})
}
}
4 changes: 2 additions & 2 deletions internal/mode/static/state/graph/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ func TestValidateFilterResponseHeaderModifier(t *testing.T) {
},
},
expectErrCount: 3,
name: "invalid response header modifier filter",
name: "response header modifier filter with disallowed header name",
},
{
validator: createAllValidValidator(),
Expand All @@ -2580,7 +2580,7 @@ func TestValidateFilterResponseHeaderModifier(t *testing.T) {
},
},
expectErrCount: 3,
name: "invalid response header modifier filter",
name: "response header modifier filter with disallowed header name prefix",
},
}

Expand Down

0 comments on commit e4f6129

Please sign in to comment.