How to do unit testing with busted in openresty?

2.1k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

I'm not really familiar with Busted, however, if you're comfortable enough using Perl; the author of Openresty has a testing scaffold specifically to test nginx-lua code named: Test::Nginx::Socket::Lua

You can find as a CPAN module here and the source code here.