From be52e2946c58622425efa36ffd8b5d1b3f14e2b9 Mon Sep 17 00:00:00 2001 From: thefosk Date: Tue, 27 Sep 2016 16:08:40 -0700 Subject: [PATCH] addressing review --- kong/tools/database_cache.lua | 13 ++----------- spec/01-unit/02-conf_loader_spec.lua | 3 ++- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/kong/tools/database_cache.lua b/kong/tools/database_cache.lua index 668d0f08d2e..ed1fd4d9161 100644 --- a/kong/tools/database_cache.lua +++ b/kong/tools/database_cache.lua @@ -1,5 +1,6 @@ local resty_lock = require "resty.lock" local cjson = require "cjson" +local pl_tablex = require "pl.tablex" local cache = ngx.shared.cache local ngx_log = ngx.log @@ -62,16 +63,6 @@ function _M.set(key, value) return true end -local function readonlytable(table) - return setmetatable({}, { - __index = table, - __newindex = function(table, key, value) - error("Attempt to modify read-only table") - end, - __metatable = false - }); -end - function _M.get(key) local value = DATA[key] @@ -85,7 +76,7 @@ function _M.get(key) -- Set the table as read-only if value ~= nil and type(value) == "table" then - value = readonlytable(value) + value = pl_tablex.readonly(value) end return value diff --git a/spec/01-unit/02-conf_loader_spec.lua b/spec/01-unit/02-conf_loader_spec.lua index 10ab69b429c..f4431afe566 100644 --- a/spec/01-unit/02-conf_loader_spec.lua +++ b/spec/01-unit/02-conf_loader_spec.lua @@ -56,11 +56,12 @@ describe("Configuration loader", function() end) it("loads custom plugins", function() local conf = assert(conf_loader(nil, { - custom_plugins = "hello-world,my-plugin" + custom_plugins = "hello-world,my-plugin, another-one" })) assert.is_nil(conf.custom_plugins) assert.True(conf.plugins["hello-world"]) assert.True(conf.plugins["my-plugin"]) + assert.True(conf.plugins["another-one"]) end) it("extracts ports and listen ips from proxy_listen/admin_listen", function() local conf = assert(conf_loader())