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 29, 2024
1 parent 9083c72 commit b31db3f
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 @@ -1948,3 +1948,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 b31db3f

Please sign in to comment.