From 70d360da27cabc7e3a95ae5c09a66400534ec206 Mon Sep 17 00:00:00 2001 From: Kapil Bansal Date: Mon, 12 Jul 2021 02:04:04 +0530 Subject: [PATCH] [ci] Add code coverage and upload to coveralls --- .github/workflows/ci.yml | 3 +++ install-dev.sh | 2 ++ openwrt-openwisp-monitoring/tests/.luacov | 5 +++++ .../tests/{env1.lua => main_env.lua} | 0 openwrt-openwisp-monitoring/tests/test_dhcp.lua | 2 +- .../tests/test_interfaces.lua | 2 +- .../tests/test_neighbors.lua | 2 +- .../tests/test_resources.lua | 2 +- runtests | 15 +++++++++------ 9 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 openwrt-openwisp-monitoring/tests/.luacov rename openwrt-openwisp-monitoring/tests/{env1.lua => main_env.lua} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1fd95b2..eba8370 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,9 @@ jobs: - name: Tests run: ./runtests + - name: Upload Coverage + run: luacov-coveralls -v -o openwrt-openwisp-monitoring/tests/luacov.report.out + build: name: Build and upload package as artifacts needs: tests diff --git a/install-dev.sh b/install-dev.sh index 9a8f9c2..09cea98 100755 --- a/install-dev.sh +++ b/install-dev.sh @@ -23,5 +23,7 @@ luarocks install luaunit luarocks install luacheck # install lua-cjson luarocks install lua-cjson +#install luacov-coveralls +luarocks install luacov-coveralls #clean rm -rf json-c libubox uci diff --git a/openwrt-openwisp-monitoring/tests/.luacov b/openwrt-openwisp-monitoring/tests/.luacov new file mode 100644 index 0000000..694a9d0 --- /dev/null +++ b/openwrt-openwisp-monitoring/tests/.luacov @@ -0,0 +1,5 @@ +return { + ['exclude'] = { + 'luaunit$' + }, +} diff --git a/openwrt-openwisp-monitoring/tests/env1.lua b/openwrt-openwisp-monitoring/tests/main_env.lua similarity index 100% rename from openwrt-openwisp-monitoring/tests/env1.lua rename to openwrt-openwisp-monitoring/tests/main_env.lua diff --git a/openwrt-openwisp-monitoring/tests/test_dhcp.lua b/openwrt-openwisp-monitoring/tests/test_dhcp.lua index c226561..327672a 100644 --- a/openwrt-openwisp-monitoring/tests/test_dhcp.lua +++ b/openwrt-openwisp-monitoring/tests/test_dhcp.lua @@ -6,7 +6,7 @@ local luaunit = require('luaunit') TestDhcp = { setUp = function() - local env = require('env1') + local env = require('main_env') package.loaded.uci = env.uci package.loaded.io = env.io end, diff --git a/openwrt-openwisp-monitoring/tests/test_interfaces.lua b/openwrt-openwisp-monitoring/tests/test_interfaces.lua index face12c..ef8d464 100644 --- a/openwrt-openwisp-monitoring/tests/test_interfaces.lua +++ b/openwrt-openwisp-monitoring/tests/test_interfaces.lua @@ -7,7 +7,7 @@ local interface_data = require('test_files/interface_data') TestInterface = { setUp = function() - local env = require('env1') + local env = require('main_env') package.loaded.uci = env.uci package.loaded.ubus = env.ubus package.loaded.io = env.io diff --git a/openwrt-openwisp-monitoring/tests/test_neighbors.lua b/openwrt-openwisp-monitoring/tests/test_neighbors.lua index bde4770..15425e4 100644 --- a/openwrt-openwisp-monitoring/tests/test_neighbors.lua +++ b/openwrt-openwisp-monitoring/tests/test_neighbors.lua @@ -6,7 +6,7 @@ local neighbor_data = require('test_files/neighbors_data') TestNeighbor = { setUp = function() - local env = require('env1') + local env = require('main_env') package.loaded.io = env.io end, tearDown = function() diff --git a/openwrt-openwisp-monitoring/tests/test_resources.lua b/openwrt-openwisp-monitoring/tests/test_resources.lua index 09cca91..d6db578 100644 --- a/openwrt-openwisp-monitoring/tests/test_resources.lua +++ b/openwrt-openwisp-monitoring/tests/test_resources.lua @@ -6,7 +6,7 @@ local resources_data = require('test_files/resources_data') TestResources = { setUp = function() - local env = require('env1') + local env = require('main_env') package.loaded.io = env.io end, tearDown = function() diff --git a/runtests b/runtests index 6c8fa20..93c8334 100755 --- a/runtests +++ b/runtests @@ -2,9 +2,12 @@ set -e cd openwrt-openwisp-monitoring/tests/ -lua test_dhcp.lua -v -lua test_interfaces.lua -v -lua test_utils.lua -v -lua test_neighbors.lua -v -lua test_resources.lua -v -lua test_wifi.lua -v +# run tests +lua -lluacov test_dhcp.lua -v +lua -lluacov test_interfaces.lua -v +lua -lluacov test_utils.lua -v +lua -lluacov test_neighbors.lua -v +lua -lluacov test_resources.lua -v +lua -lluacov test_wifi.lua -v +# send stats file to root directory +mv luacov.stats.out ../../