Skip to content

Commit 52a3547

Browse files
committed
test: add initial tests
test-run supports three types of tests: - tarantool - Test-Suite for Functional Testing - app - Another functional Test-Suite - unittest - Unit-Testing Test Suite Patch adds tests for two of supported test types: - test-app for type 'app' - test-tarantool for type 'tarantool' How-to run: $ make test
1 parent 730f2a7 commit 52a3547

27 files changed

+864
-1
lines changed

.luacheckrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ include_files = {
2626

2727
exclude_files = {
2828
"lib/tarantool-python",
29+
"test/test-tarantool/manage_cluster.test.lua",
30+
"test/test-tarantool/setopt_delimeter.test.lua",
2931
}

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
TEST_RUN_EXTRA_PARAMS?=
2+
UNIT_TEST_DIR=test/test-unit
3+
14
default:
25
false
36

4-
.PHONY: lint flake8 luacheck
57
lint: flake8 luacheck
68

79
flake8:
810
python -m flake8 *.py lib/*.py
911

1012
luacheck:
1113
luacheck --config .luacheckrc .
14+
15+
build_unit_tests:
16+
make -C $(UNIT_TEST_DIR)
17+
18+
test_integration: build_unit_tests
19+
test/test-run.py --builddir=build/ --var=build/test/var --force $(TEST_RUN_EXTRA_PARAMS)
20+
21+
.PHONY: lint flake8 luacheck test

test/.tarantoolctl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Options for test-run tarantoolctl
2+
local workdir = os.getenv('TEST_WORKDIR')
3+
default_cfg = {
4+
pid_file = workdir,
5+
wal_dir = workdir,
6+
snap_dir = workdir,
7+
vinyl_dir = workdir,
8+
logger = workdir,
9+
background = false,
10+
}
11+
12+
instance_dir = workdir
13+
14+
-- vim: set ft=lua :

test/test-app/cfg.test.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env tarantool
2+
3+
-- Test is an example of TAP test
4+
5+
local tap = require('tap')
6+
local test = tap.test('cfg')
7+
test:plan(4)
8+
9+
box.cfg{listen = box.NULL}
10+
test:is(nil, box.info.listen, 'no cfg.listen - no info.listen')
11+
12+
box.cfg{listen = '127.0.0.1:0'}
13+
test:ok(box.info.listen:match('127.0.0.1'), 'real IP in info.listen')
14+
test:ok(not box.info.listen:match(':0'), 'real port in info.listen')
15+
16+
box.cfg{listen = box.NULL}
17+
test:is(nil, box.info.listen, 'cfg.listen reset drops info.listen')
18+
19+
test:check()
20+
os.exit(0)

test/test-app/suite.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[default]
2+
core = app
3+
description = application tests
4+
is_parallel = True
5+
pretest_clean = True
6+
use_unix_sockets_iproto = True

test/test-run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../test-run.py

test/test-tarantool/box.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env tarantool
2+
local os = require('os')
3+
4+
box.cfg{
5+
listen = os.getenv("LISTEN"),
6+
memtx_memory = 107374182,
7+
pid_file = "tarantool.pid",
8+
force_recovery = true,
9+
wal_max_size = 500
10+
}
11+
12+
require('console').listen(os.getenv('ADMIN'))

test/test-tarantool/call.result

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
box.schema.user.create('test', { password = 'test' })
2+
---
3+
...
4+
box.schema.user.grant('test', 'execute,read,write', 'universe')
5+
---
6+
...
7+
exp_notation = 1e123
8+
---
9+
...
10+
function f1() return 'testing', 1, false, -1, 1.123, math.abs(exp_notation - 1e123) < 0.1, nil end
11+
---
12+
...
13+
f1()
14+
---
15+
- testing
16+
- 1
17+
- false
18+
- -1
19+
- 1.123
20+
- true
21+
- null
22+
...
23+
call f1 ()
24+
- 'testing'
25+
- 1
26+
- False
27+
- -1
28+
- 1.123
29+
- True
30+
- None
31+
f1=nil
32+
---
33+
...
34+
call f1 ()
35+
{
36+
"error": {
37+
"code": "ER_NO_SUCH_PROC",
38+
"reason": "Procedure 'f1' is not defined"
39+
}
40+
}
41+
function f1() return f1 end
42+
---
43+
...
44+
call f1 ()
45+
{
46+
"error": {
47+
"code": "ER_PROC_LUA",
48+
"reason": "unsupported Lua type 'function'"
49+
}
50+
}
51+
space = box.schema.space.create('tweedledum')
52+
---
53+
...
54+
index = space:create_index('primary', { type = 'tree' })
55+
---
56+
...
57+
eval (return {k1 = 'v1', k2 = 'v2'})()
58+
---
59+
- {"k1": "v1", "k2": "v2"}
60+
function f(...) return {k1 = 'v1', k2 = 'v2'} end
61+
---
62+
...
63+
call f()
64+
---
65+
- {"k1": "v1", "k2": "v2"}
66+
eval (return {k1 = 'v1', k2 = 'v2'})()
67+
---
68+
- {"k1": "v1", "k2": "v2"}
69+
function f(...) return {k1 = 'v1', k2 = 'v2'} end
70+
---
71+
...
72+
call f()
73+
---
74+
- {"k1": "v1", "k2": "v2"}
75+
space:drop()
76+
---
77+
...
78+
box.schema.user.drop('test')
79+
---
80+
...

test/test-tarantool/call.test.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
Original Tarantool's test box-py/call.test.py had a problem when output with
3+
running under Python 2 was not the same as with running under Python 3.
4+
5+
Fixed in commit e97425e46a77a4ac9d102c5f88062cb37e5a8da4
6+
"test: make box-py/call.test.py compatible with Python 2 and 3".
7+
"""
8+
9+
from __future__ import print_function
10+
11+
import os
12+
import sys
13+
import json
14+
15+
def call(name, *args):
16+
return iproto.call(name, *args)
17+
18+
admin("box.schema.user.create('test', { password = 'test' })")
19+
admin("box.schema.user.grant('test', 'execute,read,write', 'universe')")
20+
iproto.authenticate("test", "test")
21+
admin("exp_notation = 1e123")
22+
admin("function f1() return 'testing', 1, false, -1, 1.123, math.abs(exp_notation - 1e123) < 0.1, nil end")
23+
admin("f1()")
24+
call("f1")
25+
admin("f1=nil")
26+
call("f1")
27+
admin("function f1() return f1 end")
28+
call("f1")
29+
30+
admin("space = box.schema.space.create('tweedledum')")
31+
admin("index = space:create_index('primary', { type = 'tree' })")
32+
33+
json_dumps_kwargs=dict(sort_keys=True, separators=(', ', ': '))
34+
35+
def dump_args(*args):
36+
return json.dumps(args, **json_dumps_kwargs)[1:-1]
37+
38+
def dump_response(response):
39+
if response.return_code:
40+
return str(response)
41+
if not response.data:
42+
return ''
43+
res = []
44+
for item in response.data:
45+
res.append(json.dumps(item, **json_dumps_kwargs))
46+
return '- ' + '\n- '.join(res)
47+
48+
def lua_eval(name, *args):
49+
print("eval ({})({})".format(name, dump_args(*args)))
50+
print("---")
51+
print(dump_response(iproto.py_con.eval(name, args)))
52+
53+
def lua_call(name, *args):
54+
print("call {}({})".format(name, dump_args(*args)))
55+
print("---")
56+
print(dump_response(iproto.py_con.call(name, args)))
57+
58+
def test(expr, *args):
59+
lua_eval("return " + expr, *args)
60+
admin("function f(...) return " + expr + " end")
61+
lua_call("f", *args)
62+
63+
test("{k1 = 'v1', k2 = 'v2'}")
64+
test("{k1 = 'v1', k2 = 'v2'}")
65+
66+
admin("space:drop()")
67+
admin("box.schema.user.drop('test')")
68+
69+
iproto.py_con.close()

test/test-tarantool/engine.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"set_language.test.lua": {
3+
"memtx": {"engine": "memtx"}
4+
},
5+
"setopt_delimeter.test.lua": {
6+
"memtx": {"engine": "memtx"}
7+
},
8+
9+
"manage_cluster.test.lua": {},
10+
"*": {
11+
"memtx": {"engine": "memtx"},
12+
"vinyl": {"engine": "vinyl"}
13+
}
14+
}

0 commit comments

Comments
 (0)