luakongkong-pluginpongo2

How to generate and display coverage when running tests with Pongo for custom Kong API Gateway plugins written in Lua


I am writing a few kong custom plugins in Lua. I am using Kong 2.3.3 and Lua 5.1.

I have some test cases (unit tests + integration tests) and i am running them with pongo run -coverage option. I have already installed luacov (and also cluacov, both with luarocks install) and all my tests are passing but no luacov files are being generated with coverage data. I am not running pongo from Docker, i have installed and configured it in my local machine (which is Linux Ubuntu 20.04).

I have already tried a few things as follows:


Solution

  • A quick way to do this is to modify pongo

    Edit your pongo.sh file to:

    locate where busted is called, line 959 for me:

    "/bin/sh" "-c" "bin/busted --coverage --helper=bin/busted_helper.lua ${busted_params[*]} ${busted_files[*]};luacov;cat luacov.report.out"
    

    Install luacov, edit assets/Dockerfile after busted installation add luacov:

        && luarocks install busted-htest \
        && luarocks install luacov \
    

    pongo run will give you

    [...]
    ==============================================================================
    Summary
    ==============================================================================
    
    File                                                                              Hits  Missed Coverage
    -------------------------------------------------------------------------------------------------------
    /kong-plugin/kong/plugins/myplugin/schema.lua                                     105   1      99.06%
    /kong-plugin/spec/myplugin/01-schema_spec.lua                                     199   5      97.55%
    [...]