Skip to content

Commit

Permalink
test: rewrite TAP tests with luatest
Browse files Browse the repository at this point in the history
Patch adds a tests ported from TAP to luatest format that were
intitially implemented in commits 'Port from tap to luatest'
(549058d) and 'Rewrite tap tests to
luatest' (54d0fca) and later reverted in scope of issue with discard v2.

Follows up #90
Part of #134
  • Loading branch information
ligurio committed Oct 28, 2021
1 parent 53f04fb commit 5e69145
Show file tree
Hide file tree
Showing 15 changed files with 879 additions and 527 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
id: cache-rocks
with:
path: .rocks/
key: cache-rocks-${{ matrix.runs-on }}-01
key: cache-rocks-${{ matrix.tarantool }}-03

- run: echo $PWD/.rocks/bin >> $GITHUB_PATH

- run: tarantoolctl rocks make
- run: ./deps.sh

- name: Build module
run: |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed

- Revert all changes related to http v2 (#134).
- Rewrite TAP tests with luatest.

### Added

Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

find_package(LuaTest)

# Find Tarantool and Lua dependecies
set(TARANTOOL_FIND_REQUIRED ON)
find_package(Tarantool)
Expand All @@ -21,7 +23,7 @@ enable_testing()
set (LUA_PATH "LUA_PATH=${PROJECT_SOURCE_DIR}/?.lua\\;${PROJECT_SOURCE_DIR}/?/init.lua\\;\\;")
set (LUA_SOURCE_DIR "LUA_SOURCE_DIR=${PROJECT_SOURCE_DIR}")

add_test(http ${CMAKE_SOURCE_DIR}/test/http.test.lua)
add_test(http ${LUATEST})

set_tests_properties(http PROPERTIES ENVIRONMENT "${LUA_PATH};${LUA_SOURCE_DIR}")

Expand Down
12 changes: 12 additions & 0 deletions cmake/FindLuaTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
find_program(LUATEST luatest
HINTS .rocks/
PATH_SUFFIXES bin
DOC "Lua testing framework"
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LuaTest
REQUIRED_VARS LUATEST
)

mark_as_advanced(LUATEST)
10 changes: 10 additions & 0 deletions deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# Call this script to install test dependencies.

set -e

# Test dependencies:
tarantoolctl rocks install luatest 0.5.5

tarantoolctl rocks make
94 changes: 94 additions & 0 deletions test/helpers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
local fio = require('fio')
local http_server = require('http.server')
local http_client = require('http.client')

local helpers = table.copy(require('luatest').helpers)

helpers.base_port = 12345
helpers.base_host = '127.0.0.1'
helpers.base_uri = ('http://%s:%s'):format(helpers.base_host, helpers.base_port)

helpers.cfgserv = function()
local path = os.getenv('LUA_SOURCE_DIR') or './'
path = fio.pathjoin(path, 'test')

local httpd = http_server.new(helpers.base_host, helpers.base_port, {
app_dir = path,
log_requests = false,
log_errors = false
})
:route({path = '/abc/:cde/:def', name = 'test'}, function() end)
:route({path = '/abc'}, function() end)
:route({path = '/ctxaction'}, 'module.controller#action')
:route({path = '/absentaction'}, 'module.controller#absent')
:route({path = '/absent'}, 'module.absent#action')
:route({path = '/abc/:cde'}, function() end)
:route({path = '/abc_:cde_def'}, function() end)
:route({path = '/abc-:cde-def'}, function() end)
:route({path = '/aba*def'}, function() end)
:route({path = '/abb*def/cde', name = 'star'}, function() end)
:route({path = '/banners/:token'})
:helper('helper_title', function(self, a) return 'Hello, ' .. a end)
:route({path = '/helper', file = 'helper.html.el'})
:route({path = '/test', file = 'test.html.el' },
function(cx) return cx:render({ title = 'title: 123' }) end)

return httpd
end

local log_queue = {}

helpers.clear_log_queue = function()
log_queue = {}
end

helpers.custom_logger = {
debug = function() end,
verbose = function()
table.insert(log_queue, {
log_lvl = 'verbose',
})
end,
info = function(...)
table.insert(log_queue, {
log_lvl = 'info',
msg = string.format(...)
})
end,
warn = function(...)
table.insert(log_queue, {
log_lvl = 'warn',
msg = string.format(...)
})
end,
error = function(...)
table.insert(log_queue, {
log_lvl = 'error',
msg = string.format(...)
})
end
}

helpers.find_msg_in_log_queue = function(msg, strict)
for _, log in ipairs(log_queue) do
if not strict then
if log.msg:match(msg) then
return log
end
else
if log.msg == msg then
return log
end
end
end
end

helpers.teardown = function(httpd)
httpd:stop()
helpers.retrying({}, function()
local r = http_client.request('GET', helpers.base_uri)
return r == nil
end)
end

return helpers
Loading

0 comments on commit 5e69145

Please sign in to comment.