How can I mock the ngx
object and test my Lua files?
For example, let's say I have
-- file.lua
function computeUpstream()
-- advanced calculations!
return theCalculatedUpstream
end
ngx.var.upstream = computeUpstream()
And I want to test this file. How do I do that?
IMO the best solution is to use official OpenResty Docker images, run your configuration within container and test by series of HTTP request.
Using Docker (and may be docker-compose) one may simulate a whole infrastructure of tested application, mock backends, database with initial content, etc.
After some tests and tries you will find a way for good enough code coverage.