Skip to content

Commit 39883b9

Browse files
committed
test: rewrite TAP tests with luatest
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
1 parent 009c638 commit 39883b9

14 files changed

+888
-527
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ jobs:
2222
id: cache-rocks
2323
with:
2424
path: .rocks/
25-
key: cache-rocks-${{ matrix.runs-on }}-01
25+
key: cache-rocks-${{ matrix.runs-on }}-03
2626

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

29-
- run: tarantoolctl rocks make
29+
- run: ./deps.sh
3030

3131
- name: Build module
3232
run: |

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ if(NOT CMAKE_BUILD_TYPE)
66
endif()
77
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
88

9+
find_package(LuaTest)
10+
911
# Find Tarantool and Lua dependecies
1012
set(TARANTOOL_FIND_REQUIRED ON)
1113
find_package(Tarantool)
@@ -21,7 +23,7 @@ enable_testing()
2123
set (LUA_PATH "LUA_PATH=${PROJECT_SOURCE_DIR}/?.lua\\;${PROJECT_SOURCE_DIR}/?/init.lua\\;\\;")
2224
set (LUA_SOURCE_DIR "LUA_SOURCE_DIR=${PROJECT_SOURCE_DIR}")
2325

24-
add_test(http ${CMAKE_SOURCE_DIR}/test/http.test.lua)
26+
add_test(http ${LUATEST})
2527

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

cmake/FindLuaTest.cmake

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
find_program(LUATEST luatest
2+
HINTS .rocks/
3+
PATH_SUFFIXES bin
4+
DOC "Lua testing framework"
5+
)
6+
7+
include(FindPackageHandleStandardArgs)
8+
find_package_handle_standard_args(LuaTest
9+
REQUIRED_VARS LUATEST
10+
)
11+
12+
mark_as_advanced(LUATEST)

deps.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
# Call this script to install test dependencies.
4+
5+
set -e
6+
7+
# Test dependencies:
8+
tarantoolctl rocks install luatest 0.5.5
9+
10+
tarantoolctl rocks make

test/helpers.lua

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
local fio = require('fio')
2+
local http_server = require('http.server')
3+
local http_client = require('http.client')
4+
5+
local helpers = table.copy(require('luatest').helpers)
6+
7+
helpers.base_port = 12345
8+
helpers.base_host = '127.0.0.1'
9+
helpers.base_uri = ('http://%s:%s'):format(helpers.base_host, helpers.base_port)
10+
11+
helpers.cfgserv = function()
12+
local path = os.getenv('LUA_SOURCE_DIR') or './'
13+
path = fio.pathjoin(path, 'test')
14+
15+
local httpd = http_server.new(helpers.base_host, helpers.base_port, {
16+
app_dir = path,
17+
log_requests = false,
18+
log_errors = false
19+
})
20+
:route({path = '/abc/:cde/:def', name = 'test'}, function() end)
21+
:route({path = '/abc'}, function() end)
22+
:route({path = '/ctxaction'}, 'module.controller#action')
23+
:route({path = '/absentaction'}, 'module.controller#absent')
24+
:route({path = '/absent'}, 'module.absent#action')
25+
:route({path = '/abc/:cde'}, function() end)
26+
:route({path = '/abc_:cde_def'}, function() end)
27+
:route({path = '/abc-:cde-def'}, function() end)
28+
:route({path = '/aba*def'}, function() end)
29+
:route({path = '/abb*def/cde', name = 'star'}, function() end)
30+
:route({path = '/banners/:token'})
31+
:helper('helper_title', function(self, a) return 'Hello, ' .. a end)
32+
:route({path = '/helper', file = 'helper.html.el'})
33+
:route({path = '/test', file = 'test.html.el' },
34+
function(cx) return cx:render({ title = 'title: 123' }) end)
35+
36+
return httpd
37+
end
38+
39+
local log_queue = {}
40+
41+
helpers.clear_log_queue = function()
42+
log_queue = {}
43+
end
44+
45+
helpers.custom_logger = {
46+
debug = function() end,
47+
verbose = function()
48+
table.insert(log_queue, {
49+
log_lvl = 'verbose',
50+
})
51+
end,
52+
info = function(...)
53+
table.insert(log_queue, {
54+
log_lvl = 'info',
55+
msg = string.format(...)
56+
})
57+
end,
58+
warn = function(...)
59+
table.insert(log_queue, {
60+
log_lvl = 'warn',
61+
msg = string.format(...)
62+
})
63+
end,
64+
error = function(...)
65+
table.insert(log_queue, {
66+
log_lvl = 'error',
67+
msg = string.format(...)
68+
})
69+
end
70+
}
71+
72+
helpers.find_msg_in_log_queue = function(msg, strict)
73+
for _, log in ipairs(log_queue) do
74+
if not strict then
75+
if log.msg:match(msg) then
76+
return log
77+
end
78+
else
79+
if log.msg == msg then
80+
return log
81+
end
82+
end
83+
end
84+
end
85+
86+
helpers.teardown = function(httpd)
87+
httpd:stop()
88+
helpers.retrying({}, function()
89+
local r = http_client.request('GET', helpers.base_uri)
90+
return r == nil
91+
end)
92+
end
93+
94+
return helpers

0 commit comments

Comments
 (0)