|
| 1 | +local fio = require('fio') |
| 2 | + |
| 3 | +local g = t.group() |
| 4 | +local Server = t.Server |
| 5 | + |
| 6 | +local root = fio.dirname(fio.dirname(fio.abspath(package.search('test.helper')))) |
| 7 | +local datadir = fio.pathjoin(root, 'tmp', 'luatest_module') |
| 8 | +local command = fio.pathjoin(root, 'test', 'server_instance.lua') |
| 9 | + |
| 10 | +g.before_all(function() |
| 11 | + fio.rmtree(datadir) |
| 12 | + |
| 13 | + g.server = Server:new({ |
| 14 | + command = command, |
| 15 | + workdir = fio.pathjoin(datadir, 'common'), |
| 16 | + env = { |
| 17 | + LUA_PATH = |
| 18 | + root .. '/?.lua;' .. |
| 19 | + root .. '/?/init.lua;' .. |
| 20 | + root .. '/.rocks/share/tarantool/?.lua' |
| 21 | + }, |
| 22 | + http_port = 8182, |
| 23 | + net_box_port = 3133, |
| 24 | + }) |
| 25 | + fio.mktree(g.server.workdir) |
| 26 | + |
| 27 | + g.server:start() |
| 28 | + t.helpers.retrying({timeout = 2}, function() |
| 29 | + g.server:http_request('get', '/ping') |
| 30 | + end) |
| 31 | + |
| 32 | + g.server:connect_net_box() |
| 33 | +end) |
| 34 | + |
| 35 | +g.after_all(function() |
| 36 | + g.server:stop() |
| 37 | + fio.rmtree(datadir) |
| 38 | +end) |
| 39 | + |
| 40 | +g.test_exec_without_t = function() |
| 41 | + local actual = g.server:exec(function() |
| 42 | + return 1 + 1 |
| 43 | + end) |
| 44 | + t.assert_equals(actual, 2) |
| 45 | +end |
| 46 | + |
| 47 | +g.test_exec_with_global_variable = function() |
| 48 | + g.server:exec(function() |
| 49 | + t.assert_equals(1, 1) |
| 50 | + end) |
| 51 | + t.assert_equals(1, 1) |
| 52 | +end |
| 53 | + |
| 54 | +g.test_exec_with_local_variable = function() |
| 55 | + g.server:exec(function() |
| 56 | + local t = require('luatest') |
| 57 | + t.assert_equals(1, 1) |
| 58 | + end) |
| 59 | + t.assert_equals(1, 1) |
| 60 | +end |
| 61 | + |
| 62 | +g.test_exec_with_local_duplicate = function() |
| 63 | + g.server:exec(function() |
| 64 | + local tt = require('luatest') |
| 65 | + t.assert_equals(1, 1) |
| 66 | + tt.assert_equals(1, 1) |
| 67 | + t.assert_equals(tt, t) |
| 68 | + end) |
| 69 | +end |
| 70 | + |
| 71 | +g.test_eval_with_t = function() |
| 72 | + local actual = g.server:eval([[ |
| 73 | + t.assert_equals(1, 1) |
| 74 | + return 1 |
| 75 | + ]]) |
| 76 | + t.assert_equals(actual, 1) |
| 77 | +end |
| 78 | + |
| 79 | +g.before_test('test_exec_when_lua_path_is_unset', function() |
| 80 | + -- Setup custom server without LUA_PATH variable |
| 81 | + local workdir = fio.tempdir() |
| 82 | + local log = fio.pathjoin(workdir, 'bad_env_server.log') |
| 83 | + g.bad_env_server = Server:new({ |
| 84 | + command = command, |
| 85 | + workdir = workdir, |
| 86 | + env = { |
| 87 | + TARANTOOL_LOG = log |
| 88 | + }, |
| 89 | + http_port = 8183, |
| 90 | + net_box_port = 3134, |
| 91 | + }) |
| 92 | + |
| 93 | + fio.mktree(g.bad_env_server.workdir) |
| 94 | + |
| 95 | + g.bad_env_server:start() |
| 96 | + |
| 97 | + t.helpers.retrying({timeout = 2}, function() |
| 98 | + g.bad_env_server:http_request('get', '/ping') |
| 99 | + end) |
| 100 | + |
| 101 | + g.bad_env_server:connect_net_box() |
| 102 | +end) |
| 103 | + |
| 104 | +g.test_exec_when_lua_path_is_unset = function() |
| 105 | + g.bad_env_server:exec(function() return 1 + 1 end) |
| 106 | + |
| 107 | + t.assert( |
| 108 | + g.bad_env_server:grep_log( |
| 109 | + "W> LUA_PATH is unset or incorrect, module 'luatest' not found" |
| 110 | + ) |
| 111 | + ) |
| 112 | +end |
| 113 | + |
| 114 | +g.after_test('test_exec_when_lua_path_is_unset', function() |
| 115 | + g.bad_env_server:drop() |
| 116 | +end) |
0 commit comments