-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
14 changed files
with
888 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.