diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8b6e8d..16a96b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,8 +50,9 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Run tests and code coverage analysis - run: make -C build coverage + - name: Run tests without code coverage analysis + run: make -C build luatest-no-coverage + if: matrix.coveralls != true - name: Send code coverage to coveralls.io run: make -C build coveralls diff --git a/CMakeLists.txt b/CMakeLists.txt index 9de6055..ded25b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,12 @@ add_custom_target(luatest COMMENT "Run regression tests" ) +add_custom_target(luatest-no-coverage + COMMAND ${LUATEST} -v + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Run regression tests without coverage" +) + add_custom_target(coverage COMMAND ${LUACOV} ${PROJECT_SOURCE_DIR} && grep -A999 '^Summary' ${CODE_COVERAGE_REPORT} DEPENDS ${CODE_COVERAGE_STATS} @@ -49,7 +55,7 @@ add_custom_target(coverage ) if(DEFINED ENV{GITHUB_TOKEN}) - set(COVERALLS_COMMAND ${LUACOVCOVERALLS} --include ^http ^roles --verbose --repo-token $ENV{GITHUB_TOKEN}) + set(COVERALLS_COMMAND ${LUACOVCOVERALLS} --include ^http --verbose --repo-token $ENV{GITHUB_TOKEN}) else() set(COVERALLS_COMMAND ${CMAKE_COMMAND} -E echo "Skipped uploading to coveralls.io: no token.") endif() diff --git a/test/integration/httpd_role_test.lua b/test/integration/httpd_role_test.lua deleted file mode 100644 index db3e24e..0000000 --- a/test/integration/httpd_role_test.lua +++ /dev/null @@ -1,85 +0,0 @@ -local t = require('luatest') -local treegen = require('luatest.treegen') -local server = require('luatest.server') -local fio = require('fio') -local fun = require('fun') -local yaml = require('yaml') - -local helpers = require('test.helpers') -local httpd_role = require('roles.httpd') -local mock_role = require('test.mocks.mock_role') - -local g = t.group() - -g.after_each(function() - httpd_role.stop() -end) - -g.test_httpd_role_usage = function() - helpers.skip_if_not_tarantool3() - - local config = { - credentials = { - users = { - guest = { - roles = {'super'}, - }, - }, - }, - iproto = { - listen = {{uri = 'unix/:./{{ instance_name }}.iproto'}}, - }, - groups = { - ['group-001'] = { - replicasets = { - ['replicaset-001'] = { - instances = { - ['instance-001'] = {}, - }, - }, - }, - }, - }, - roles_cfg = { - httpd = { - default = { - listen = 13000, - }, - additional = { - listen = 13001, - } - }, - mock_role = { - { - id = 1, - }, - { - id = 2, - name = 'additional', - }, - }, - }, - } - local dir = treegen.prepare_directory({}, {}) - - local config_file = treegen.write_file(dir, 'config.yaml', - yaml.encode(config)) - local opts = {config_file = config_file, chdir = dir} - g.server = server:new(fun.chain(opts, {alias = 'instance-001'}):tomap()) - - local ROOT = fio.dirname(fio.dirname(fio.abspath(package.search('http.server')))) - - g.server.env.LUA_PATH = ROOT .. '/?.lua;' .. - ROOT .. '/?/init.lua;' .. - ROOT .. '/.rocks/share/tarantool/?.lua;' .. - ROOT .. '/.rocks/share/tarantool/?/init.lua' - g.server.env.LUA_CPATH = ROOT .. '/.rocks/lib/tarantool/?.so;' .. - ROOT .. '/.rocks/lib/tarantool/?/?.so' - g.server:start() - - httpd_role.apply(config.roles_cfg.httpd) - mock_role.apply(config.roles_cfg.mock_role, httpd_role) - - t.assert_equals(mock_role.get_server_port(1), 13000) - t.assert_equals(mock_role.get_server_port(2), 13001) -end diff --git a/test/unit/httpd_role_test.lua b/test/unit/httpd_role_test.lua deleted file mode 100644 index f264c67..0000000 --- a/test/unit/httpd_role_test.lua +++ /dev/null @@ -1,183 +0,0 @@ -local t = require('luatest') -local g = t.group() - -local httpd_role = require('roles.httpd') - -g.after_each(function() - httpd_role.stop() -end) - -local validation_cases = { - ["not_table"] = { - cfg = 42, - err = "configuration must be a table, got number", - }, - ["name_not_string"] = { - cfg = { - [42] = { - listen = 8081, - }, - }, - err = "name of the server must be a string", - }, - ["listen_not_exist"] = { - cfg = { - server = { - listen = nil, - }, - }, - err = "failed to parse http 'listen' param: must exist", - }, - ["listen_not_string_and_not_number"] = { - cfg = { - server = { - listen = {}, - }, - }, - err = "failed to parse http 'listen' param: must be a string or a number, got table", - }, - ["listen_port_too_small"] = { - cfg = { - server = { - listen = 0, - }, - }, - err = "failed to parse http 'listen' param: port must be in the range [1, 65535]", - }, - ["listen_port_in_range"] = { - cfg = { - server = { - listen = 8081, - }, - }, - }, - ["listen_port_too_big"] = { - cfg = { - server = { - listen = 65536, - }, - }, - err = "failed to parse http 'listen' param: port must be in the range [1, 65535]", - }, - ["listen_uri_no_port"] = { - cfg = { - server = { - listen = "localhost", - }, - }, - err = "failed to parse http 'listen' param: URI must contain a port", - }, - ["listen_uri_port_too_small"] = { - cfg = { - server = { - listen = "localhost:0", - }, - }, - err = "failed to parse http 'listen' param: port must be in the range [1, 65535]", - }, - ["listen_uri_with_port_in_range"] = { - cfg = { - server = { - listen = "localhost:8081", - }, - }, - }, - ["listen_uri_port_too_big"] = { - cfg = { - server = { - listen = "localhost:65536", - }, - }, - err = "failed to parse http 'listen' param: port must be in the range [1, 65535]", - }, - ["listen_uri_port_not_number"] = { - cfg = { - server = { - listen = "localhost:foo", - }, - }, - err = "failed to parse http 'listen' param: URI port must be a number", - }, - ["listen_uri_non_unix_scheme"] = { - cfg = { - server = { - listen = "http://localhost:123", - }, - }, - err = "failed to parse http 'listen' param: URI scheme is not supported", - }, - ["listen_uri_login_password"] = { - cfg = { - server = { - listen = "login:password@localhost:123", - }, - }, - err = "failed to parse http 'listen' param: URI login and password are not supported", - }, - ["listen_uri_query"] = { - cfg = { - server = { - listen = "localhost:123/?foo=bar", - }, - }, - err = "failed to parse http 'listen' param: URI query component is not supported", - }, -} - -for name, case in pairs(validation_cases) do - local test_name = ('test_validate_http_%s%s'):format( - (case.err ~= nil) and 'fails_on_' or 'success_for_', - name - ) - - g[test_name] = function() - local ok, res = pcall(httpd_role.validate, case.cfg) - - if case.err ~= nil then - t.assert_not(ok) - t.assert_str_contains(res, case.err) - else - t.assert(ok) - t.assert_is(res, nil) - end - end -end - -g['test_get_default_without_apply'] = function() - local result = httpd_role.get_server() - t.assert_is(result, nil) -end - -g['test_get_default_no_default'] = function() - local cfg = { - not_a_default = { - listen = 13000, - }, - } - - httpd_role.apply(cfg) - - local result = httpd_role.get_server() - t.assert_is(result, nil) -end - -g['test_get_default'] = function() - local cfg = { - [httpd_role.DEFAULT_SERVER_NAME] = { - listen = 13001, - }, - } - - httpd_role.apply(cfg) - - local result = httpd_role.get_server() - t.assert_not_equals(result, nil) - t.assert_is(result.httpd.port, 13001) -end - -g['test_get_server_bad_type'] = function() - local ok, res = pcall(httpd_role.get_server, {}) - - t.assert_not(ok) - t.assert_str_contains(res, '?string expected, got table') -end