Skip to content

Commit

Permalink
test: replace testcase by luatest's testcases
Browse files Browse the repository at this point in the history
The tests `array.test.lua` and `map.test.lua` require the remote
Tarantool instance for running testcases. When tests are executed
by test-run.py, it runs this Tarantool instance. The testcases
that require the remote instance were ported to luatest to make
tests able to run with ctest. The testcases `builtins-13.1` and
`builtins-14.1` are companion testcases and were moved as well.

Required by patches for CTest support, because allows to
execute aforementioned tests without test-run.py.

NO_CHANGELOG=codehealth
NO_DOC=codehealth
NO_TEST=codehealth
  • Loading branch information
ligurio authored and Buristan committed Oct 8, 2024
1 parent c26c071 commit 47295fd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
30 changes: 30 additions & 0 deletions test/sql-luatest/array_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local server = require('luatest.server')
local t = require('luatest')

local g = t.group()

g.before_all(function()
g.server = server:new({alias = 'array'})
g.server:start()
end)

g.after_all(function()
g.server:stop()
end)

-- Make sure that ARRAY values can be used as bound variable.
g.test_array_binding_local = function()
g.server:exec(function()
local sql = [[SELECT #a;]]
local arg = {{['#a'] = {1, 2, 3}}}
t.assert_equals(box.execute(sql, arg).rows[1][1], {1, 2, 3})
end)
end

g.test_array_binding_remote = function()
local conn = g.server.net_box
local ok, res = pcall(conn.execute, conn, [[SELECT #a;]],
{{['#a'] = {1, 2, 3}}})
t.assert_equals(ok, true)
t.assert_equals(res.rows[1][1], {1, 2, 3})
end
18 changes: 18 additions & 0 deletions test/sql-luatest/map_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,21 @@ g.test_map_9 = function()
t.assert_equals(box.execute(sql).rows, res)
end)
end

-- Make sure that MAP values can be used as a bound variable.
g.test_map_binding_local = function()
g.server:exec(function()
local sql = [[SELECT #a;]]
local arg = {{['#a'] = {abc = 2, [1] = 3}}}
local res = {abc = 2, [1] = 3}
t.assert_equals(box.execute(sql, arg).rows[1][1], res)
end)
end

g.test_map_binding_remote = function()
local conn = g.server.net_box
local ok, res = pcall(conn.execute, conn, [[SELECT #a;]],
{{['#a'] = {abc = 2, [1] = 3}}})
t.assert_equals(ok, true)
t.assert_equals(res.rows[1][1], {abc = 2, [1] = 3})
end
27 changes: 1 addition & 26 deletions test/sql-tap/array.test.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env tarantool
local test = require("sqltester")
test:plan(117)
test:plan(115)

box.schema.func.create('a1', {
language = 'Lua',
Expand Down Expand Up @@ -1025,31 +1025,6 @@ test:do_execsql_test(
"array"
})

-- Make sure that ARRAY values can be used as bound variable.
test:do_test(
"builtins-14.1",
function()
local res = box.execute([[SELECT #a;]], {{['#a'] = {1, 2, 3}}})
return {res.rows[1][1]}
end, {
{1, 2, 3}
})

local remote = require('net.box')
box.cfg{listen = os.getenv('LISTEN')}
box.schema.user.grant('guest', 'execute', 'sql')
local cn = remote.connect(box.cfg.listen)
test:do_test(
"builtins-14.2",
function()
local res = cn:execute([[SELECT #a;]], {{['#a'] = {1, 2, 3}}})
return {res.rows[1][1]}
end, {
{1, 2, 3}
})
cn:close()
box.schema.user.revoke('guest', 'execute', 'sql')

box.execute([[DROP TABLE t1;]])
box.execute([[DROP TABLE t;]])

Expand Down
27 changes: 1 addition & 26 deletions test/sql-tap/map.test.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env tarantool
local test = require("sqltester")
test:plan(112)
test:plan(110)

box.schema.func.create('m1', {
language = 'Lua',
Expand Down Expand Up @@ -981,31 +981,6 @@ test:do_catchsql_test(
1, "Failed to execute SQL statement: wrong arguments for function ZEROBLOB()"
})

-- Make sure that MAP values can be used as a bound variable.
test:do_test(
"builtins-13.1",
function()
local res = box.execute([[SELECT #a;]], {{['#a'] = {abc = 2, [1] = 3}}})
return {res.rows[1][1]}
end, {
{abc = 2, [1] = 3}
})

local remote = require('net.box')
box.cfg{listen = os.getenv('LISTEN')}
box.schema.user.grant('guest', 'execute', 'sql')
local cn = remote.connect(box.cfg.listen)
test:do_test(
"builtins-13.2",
function()
local res = cn:execute([[SELECT #a;]], {{['#a'] = {abc = 2, [1] = 3}}})
return {res.rows[1][1]}
end, {
{abc = 2, [1] = 3}
})
cn:close()
box.schema.user.revoke('guest', 'execute', 'sql')

box.execute([[DROP TABLE t1;]])
box.execute([[DROP TABLE t;]])

Expand Down

0 comments on commit 47295fd

Please sign in to comment.