Disclaimer: I’m a front-end developer and my only Lua experience was hearing about a Lua table data structure 10 years ago and adding that to MooTools (pre
I’m writing a plugin based on some prior “art” and am trying to write some tests for it. The meat of the plugin is the following:
function _M.execute (conf) local cookie = restycookie:new() local allowedVars = template.getCommonAllowedVars(conf) local cookieName = template.apply(conf.cookie_name, nil, nil, allowedVars) ... local request_cookie_value = cookie:get(cookieName) if request_cookie_value == nil then local path = kong.request.get_path() if handle_route(conf.routes, path) then conf.protocol = conf.scheme conf.path = conf.path_prefix return dynamic_service_access.execute(conf) end end end
Someone else on my team has mocked Kong (at least some of the methods) so we can mock requests in another plugin’s tests. With that in place when I call the execute method above in the test I get an error saying
/usr/local/share/lua/5.1/resty/cookie.lua:103: API disabled in the current context stack traceback: /usr/local/openresty/lualib/resty/core/var.lua:73: in function '__index' /usr/local/share/lua/5.1/resty/cookie.lua:103: in function 'new' .../share/lua/5.1/kong/plugins/no-cookie-routing/access.lua:22: in function 'execute' test/access.lua:47: in function <test/access.lua:35>
I’d rather not mock the resty cookie, but even if I do that I start getting the same error about lua request due to the
get_path() call. What is the appropriate way to test this and is there a way to mock the context/ctx on Kong?