1
votes

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?

1
you can ask in openresty group groups.google.com/forum/#!forum/openresty-en - Larry.He

1 Answers

0
votes

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.