Skip to content

Commit 861a33f

Browse files
lua: fix code style in test scripts
Added standard .luacheckrc config. Added indentation to box.once blocks. Fix trailing spaces and add missing spaces to mathematical expressions. Set global variables through rawset.
1 parent 8f1cef6 commit 861a33f

File tree

4 files changed

+114
-83
lines changed

4 files changed

+114
-83
lines changed

.luacheckrc

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
redefined = false
2+
3+
globals = {
4+
'box',
5+
'utf8',
6+
'checkers',
7+
'_TARANTOOL'
8+
}
9+
10+
include_files = {
11+
'**/*.lua',
12+
'*.luacheckrc',
13+
'*.rockspec'
14+
}
15+
16+
exclude_files = {
17+
'**/*.rocks/'
18+
}
19+
20+
max_line_length = 120
21+
22+
ignore = {
23+
"212/self", -- Unused argument <self>.
24+
"411", -- Redefining a local variable.
25+
"421", -- Shadowing a local variable.
26+
"431", -- Shadowing an upvalue.
27+
"432", -- Shadowing an upvalue argument.
28+
}

config.lua

+44-43
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,56 @@ box.cfg{
55
}
66

77
box.once("init", function()
8-
local s = box.schema.space.create('test', {
9-
id = 512,
10-
if_not_exists = true,
11-
})
12-
s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true})
8+
local s = box.schema.space.create('test', {
9+
id = 512,
10+
if_not_exists = true,
11+
})
12+
s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true})
1313

14-
local st = box.schema.space.create('schematest', {
15-
id = 514,
16-
temporary = true,
17-
if_not_exists = true,
18-
field_count = 7,
19-
format = {
20-
{name = "name0", type = "unsigned"},
21-
{name = "name1", type = "unsigned"},
22-
{name = "name2", type = "string"},
23-
{name = "name3", type = "unsigned"},
24-
{name = "name4", type = "unsigned"},
25-
{name = "name5", type = "string"},
26-
},
27-
})
28-
st:create_index('primary', {
29-
type = 'hash',
30-
parts = {1, 'uint'},
31-
unique = true,
32-
if_not_exists = true,
33-
})
34-
st:create_index('secondary', {
35-
id = 3,
36-
type = 'tree',
37-
unique = false,
38-
parts = { 2, 'uint', 3, 'string' },
39-
if_not_exists = true,
40-
})
41-
st:truncate()
14+
local st = box.schema.space.create('schematest', {
15+
id = 514,
16+
temporary = true,
17+
if_not_exists = true,
18+
field_count = 7,
19+
format = {
20+
{name = "name0", type = "unsigned"},
21+
{name = "name1", type = "unsigned"},
22+
{name = "name2", type = "string"},
23+
{name = "name3", type = "unsigned"},
24+
{name = "name4", type = "unsigned"},
25+
{name = "name5", type = "string"},
26+
},
27+
})
28+
st:create_index('primary', {
29+
type = 'hash',
30+
parts = {1, 'uint'},
31+
unique = true,
32+
if_not_exists = true,
33+
})
34+
st:create_index('secondary', {
35+
id = 3,
36+
type = 'tree',
37+
unique = false,
38+
parts = { 2, 'uint', 3, 'string' },
39+
if_not_exists = true,
40+
})
41+
st:truncate()
4242

43-
--box.schema.user.grant('guest', 'read,write,execute', 'universe')
44-
box.schema.func.create('box.info')
45-
box.schema.func.create('simple_incr')
43+
--box.schema.user.grant('guest', 'read,write,execute', 'universe')
44+
box.schema.func.create('box.info')
45+
box.schema.func.create('simple_incr')
4646

47-
-- auth testing: access control
48-
box.schema.user.create('test', {password = 'test'})
49-
box.schema.user.grant('test', 'execute', 'universe')
50-
box.schema.user.grant('test', 'read,write', 'space', 'test')
51-
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
47+
-- auth testing: access control
48+
box.schema.user.create('test', {password = 'test'})
49+
box.schema.user.grant('test', 'execute', 'universe')
50+
box.schema.user.grant('test', 'read,write', 'space', 'test')
51+
box.schema.user.grant('test', 'read,write', 'space', 'schematest')
5252
end)
5353

54-
function simple_incr(a)
55-
return a+1
54+
local function simple_incr(a)
55+
return a + 1
5656
end
57+
rawset(_G, 'simple_incr', simple_incr)
5758

5859
box.space.test:truncate()
5960

multi/config.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ box.cfg{
77
}
88

99
-- Function to call for getting address list, part of tarantool/multi API.
10-
get_cluster_nodes = nodes_load.get_cluster_nodes
10+
local get_cluster_nodes = nodes_load.get_cluster_nodes
11+
rawset(_G, 'get_cluster_nodes', get_cluster_nodes)
1112

1213
box.once("init", function()
1314
box.schema.user.create('test', { password = 'test' })

queue/config.lua

+40-39
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
1-
queue = require('queue')
1+
local queue = require('queue')
2+
rawset(_G, 'queue', queue)
23

34
-- Do not set listen for now so connector won't be
45
-- able to send requests until everything is configured.
56
box.cfg{
67
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
78
}
89

9-
box.once("init", function()
10-
box.schema.user.create('test', {password = 'test'})
11-
box.schema.func.create('queue.tube.test_queue:ack')
12-
box.schema.func.create('queue.tube.test_queue:put')
13-
box.schema.func.create('queue.tube.test_queue:drop')
14-
box.schema.func.create('queue.tube.test_queue:peek')
15-
box.schema.func.create('queue.tube.test_queue:kick')
16-
box.schema.func.create('queue.tube.test_queue:take')
17-
box.schema.func.create('queue.tube.test_queue:delete')
18-
box.schema.func.create('queue.tube.test_queue:release')
19-
box.schema.func.create('queue.tube.test_queue:bury')
20-
box.schema.func.create('queue.statistics')
21-
box.schema.user.grant('test', 'create', 'space')
22-
box.schema.user.grant('test', 'write', 'space', '_schema')
23-
box.schema.user.grant('test', 'write', 'space', '_space')
24-
box.schema.user.grant('test', 'read,write', 'space', '_space_sequence')
25-
box.schema.user.grant('test', 'write', 'space', '_index')
26-
box.schema.user.grant('test', 'read, write', 'space', '_queue_session_ids')
27-
box.schema.user.grant('test', 'execute', 'universe')
28-
box.schema.user.grant('test', 'read,write', 'space', '_queue')
29-
box.schema.user.grant('test', 'read,write', 'space', '_schema')
30-
box.schema.user.grant('test', 'read,write', 'space', '_space')
31-
box.schema.user.grant('test', 'read,write', 'space', '_index')
32-
box.schema.user.grant('test', 'read,write', 'space', '_queue_consumers')
33-
box.schema.user.grant('test', 'read,write', 'space', '_priv')
34-
box.schema.user.grant('test', 'read,write', 'space', '_queue_taken_2')
35-
if box.space._trigger ~= nil then
36-
box.schema.user.grant('test', 'read', 'space', '_trigger')
37-
end
38-
if box.space._fk_constraint ~= nil then
39-
box.schema.user.grant('test', 'read', 'space', '_fk_constraint')
40-
end
41-
if box.space._ck_constraint ~= nil then
42-
box.schema.user.grant('test', 'read', 'space', '_ck_constraint')
43-
end
44-
if box.space._func_index ~= nil then
45-
box.schema.user.grant('test', 'read', 'space', '_func_index')
46-
end
10+
box.once("init", function()
11+
box.schema.user.create('test', {password = 'test'})
12+
box.schema.func.create('queue.tube.test_queue:ack')
13+
box.schema.func.create('queue.tube.test_queue:put')
14+
box.schema.func.create('queue.tube.test_queue:drop')
15+
box.schema.func.create('queue.tube.test_queue:peek')
16+
box.schema.func.create('queue.tube.test_queue:kick')
17+
box.schema.func.create('queue.tube.test_queue:take')
18+
box.schema.func.create('queue.tube.test_queue:delete')
19+
box.schema.func.create('queue.tube.test_queue:release')
20+
box.schema.func.create('queue.tube.test_queue:bury')
21+
box.schema.func.create('queue.statistics')
22+
box.schema.user.grant('test', 'create', 'space')
23+
box.schema.user.grant('test', 'write', 'space', '_schema')
24+
box.schema.user.grant('test', 'write', 'space', '_space')
25+
box.schema.user.grant('test', 'read,write', 'space', '_space_sequence')
26+
box.schema.user.grant('test', 'write', 'space', '_index')
27+
box.schema.user.grant('test', 'read, write', 'space', '_queue_session_ids')
28+
box.schema.user.grant('test', 'execute', 'universe')
29+
box.schema.user.grant('test', 'read,write', 'space', '_queue')
30+
box.schema.user.grant('test', 'read,write', 'space', '_schema')
31+
box.schema.user.grant('test', 'read,write', 'space', '_space')
32+
box.schema.user.grant('test', 'read,write', 'space', '_index')
33+
box.schema.user.grant('test', 'read,write', 'space', '_queue_consumers')
34+
box.schema.user.grant('test', 'read,write', 'space', '_priv')
35+
box.schema.user.grant('test', 'read,write', 'space', '_queue_taken_2')
36+
if box.space._trigger ~= nil then
37+
box.schema.user.grant('test', 'read', 'space', '_trigger')
38+
end
39+
if box.space._fk_constraint ~= nil then
40+
box.schema.user.grant('test', 'read', 'space', '_fk_constraint')
41+
end
42+
if box.space._ck_constraint ~= nil then
43+
box.schema.user.grant('test', 'read', 'space', '_ck_constraint')
44+
end
45+
if box.space._func_index ~= nil then
46+
box.schema.user.grant('test', 'read', 'space', '_func_index')
47+
end
4748
end)
4849

4950
-- Set listen only when every other thing is configured.

0 commit comments

Comments
 (0)