Search code examples
unit-testingnginxluaopenrestylua-busted

How to do unit testing with busted in openresty?


I have a bunch of lua files which I use to handle different urls in nginx, like this:

location /tag {
    set $env       'prod';
    set $redis_ttl 7776000;
    content_by_lua_file 'conf/match.lua';
    log_by_lua_file     'conf/log.lua';
}

Each file is a simple script, without any module structure. When the number of lines and files were low, I tested everything manually, but now I feel like I need to do unit testing. Busted framework looks like a logical choice, though I can't understand how to fit it right into openresty model.


Solution

  • Late to the party, but here's how you can use Busted in a transparent way with OpenResty: https://github.com/lunarmodules/busted/issues/414#issuecomment-792614808