How to do unit testing with busted in openresty?

By | January 12, 2018
Questions:

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.

Answers:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *