Skip to content

Commit

Permalink
spec: overwrite original ngx.header in tests that mutate it
Browse files Browse the repository at this point in the history
The .__newindex method of the ngx.header metatable raises "API disabled
in the current context" when trying to mutate it from the busted tests.
To avoid that, we overwrite ngx.header in the tests that need to modify
it.
  • Loading branch information
davidor committed Feb 26, 2018
1 parent 96bf81e commit cd26d24
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions spec/policy/cors/cors_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ describe('CORS policy', function()

describe('.header_filter', function()
before_each(function()
local headers = {}
stub(ngx.header, function() return headers end)
-- Replace original ngx.header. Openresty does not allow to modify it when
-- running busted tests.
ngx.header = {}
end)

describe('when the policy configuration defines CORS headers', function()
Expand Down
5 changes: 3 additions & 2 deletions spec/policy/headers/headers_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ describe('Headers policy', function()
local response_headers = 'response' -- header_filter() only modifies resp headers

before_each(function()
local headers = {}
stub(ngx.header, function() return headers end)
-- Replace original ngx.header. Openresty does not allow to modify it when
-- running busted tests.
ngx.header = {}
end)

describe('the push operation', function()
Expand Down
4 changes: 4 additions & 0 deletions spec/proxy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ describe('Proxy', function()
describe(':rewrite', function()
local service
before_each(function()
-- Replace original ngx.header. Openresty does not allow to modify it when
-- running busted tests.
ngx.header = {}

ngx.var = { backend_endpoint = 'http://localhost:1853', uri = '/a/uri' }
ngx.req = { get_method = function () return 'GET' end}
service = Service.new({ extract_usage = function() end })
Expand Down

0 comments on commit cd26d24

Please sign in to comment.