Skip to content

Commit

Permalink
linked_list: raise error when trying to modify read-only list
Browse files Browse the repository at this point in the history
  • Loading branch information
davidor committed Nov 14, 2017
1 parent 31fbcd1 commit b108fa6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion apicast/src/linked_list.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local setmetatable = setmetatable
local error = error

local _M = {

Expand All @@ -14,7 +15,9 @@ end

local ro_mt = {
__index = __index,
__newindex = noop,
__newindex = function()
error("readonly list")
end,
}

local rw_mt = {
Expand Down
2 changes: 1 addition & 1 deletion spec/linked_list_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('linked_list', function()
it('returns a list that cannot be modified', function()
local list = linked_list.readonly({ a = 1 })

list.abc = 123
assert.has_error(function() list.abc = 123 end, 'readonly list')
assert.is_nil(list.abc)
end)

Expand Down
6 changes: 3 additions & 3 deletions spec/policy_chain_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ describe('policy_chain', function()

local shared_data = chain:export()

-- This does not raise, but it does not do anything.
shared_data.new_shared_data = 'some_data'

assert.has_error(function()
shared_data.new_shared_data = 'some_data'
end, 'readonly list')
assert.is_nil(shared_data.new_shared_data)
end)

Expand Down

0 comments on commit b108fa6

Please sign in to comment.