From 491e9aa93bbbb2164fc1044ec442e7401290160f Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Thu, 3 Feb 2022 19:17:06 +0300 Subject: [PATCH] lua: fix code style it 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. --- .luacheckrc | 5 +++ config.lua | 87 ++++++++++++++++++++++++------------------------ multi/config.lua | 3 +- queue/config.lua | 79 +++++++++++++++++++++---------------------- 4 files changed, 91 insertions(+), 83 deletions(-) create mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 000000000..392823cc2 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,5 @@ +redefined = false +globals = {'box', 'utf8', 'checkers', '_TARANTOOL'} +include_files = {'**/*.lua', '*.luacheckrc', '*.rockspec'} +exclude_files = {'**/*.rocks/'} +max_line_length = 120 diff --git a/config.lua b/config.lua index d06e05395..2528e7b81 100644 --- a/config.lua +++ b/config.lua @@ -5,55 +5,56 @@ box.cfg{ } box.once("init", function() -local s = box.schema.space.create('test', { - id = 512, - if_not_exists = true, -}) -s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true}) + local s = box.schema.space.create('test', { + id = 512, + if_not_exists = true, + }) + s:create_index('primary', {type = 'tree', parts = {1, 'uint'}, if_not_exists = true}) -local st = box.schema.space.create('schematest', { - id = 514, - temporary = true, - if_not_exists = true, - field_count = 7, - format = { - {name = "name0", type = "unsigned"}, - {name = "name1", type = "unsigned"}, - {name = "name2", type = "string"}, - {name = "name3", type = "unsigned"}, - {name = "name4", type = "unsigned"}, - {name = "name5", type = "string"}, - }, -}) -st:create_index('primary', { - type = 'hash', - parts = {1, 'uint'}, - unique = true, - if_not_exists = true, -}) -st:create_index('secondary', { - id = 3, - type = 'tree', - unique = false, - parts = { 2, 'uint', 3, 'string' }, - if_not_exists = true, -}) -st:truncate() + local st = box.schema.space.create('schematest', { + id = 514, + temporary = true, + if_not_exists = true, + field_count = 7, + format = { + {name = "name0", type = "unsigned"}, + {name = "name1", type = "unsigned"}, + {name = "name2", type = "string"}, + {name = "name3", type = "unsigned"}, + {name = "name4", type = "unsigned"}, + {name = "name5", type = "string"}, + }, + }) + st:create_index('primary', { + type = 'hash', + parts = {1, 'uint'}, + unique = true, + if_not_exists = true, + }) + st:create_index('secondary', { + id = 3, + type = 'tree', + unique = false, + parts = { 2, 'uint', 3, 'string' }, + if_not_exists = true, + }) + st:truncate() ---box.schema.user.grant('guest', 'read,write,execute', 'universe') -box.schema.func.create('box.info') -box.schema.func.create('simple_incr') + --box.schema.user.grant('guest', 'read,write,execute', 'universe') + box.schema.func.create('box.info') + box.schema.func.create('simple_incr') --- auth testing: access control -box.schema.user.create('test', {password = 'test'}) -box.schema.user.grant('test', 'execute', 'universe') -box.schema.user.grant('test', 'read,write', 'space', 'test') -box.schema.user.grant('test', 'read,write', 'space', 'schematest') + -- auth testing: access control + box.schema.user.create('test', {password = 'test'}) + box.schema.user.grant('test', 'execute', 'universe') + box.schema.user.grant('test', 'read,write', 'space', 'test') + box.schema.user.grant('test', 'read,write', 'space', 'schematest') end) -function simple_incr(a) - return a+1 +local function simple_incr(a) + return a + 1 end +rawset(_G, 'simple_incr', simple_incr) box.space.test:truncate() diff --git a/multi/config.lua b/multi/config.lua index fbd4befa1..25b0eb4f9 100644 --- a/multi/config.lua +++ b/multi/config.lua @@ -7,7 +7,8 @@ box.cfg{ } -- Function to call for getting address list, part of tarantool/multi API. -get_cluster_nodes = nodes_load.get_cluster_nodes +local get_cluster_nodes = nodes_load.get_cluster_nodes +rawset(_G, 'get_cluster_nodes', get_cluster_nodes) box.once("init", function() box.schema.user.create('test', { password = 'test' }) diff --git a/queue/config.lua b/queue/config.lua index 767f259ad..cb64f4df8 100644 --- a/queue/config.lua +++ b/queue/config.lua @@ -1,4 +1,5 @@ -queue = require('queue') +local queue = require('queue') +rawset(_G, 'queue', queue) -- Do not set listen for now so connector won't be -- able to send requests until everything is configured. @@ -6,44 +7,44 @@ box.cfg{ work_dir = os.getenv("TEST_TNT_WORK_DIR"), } -box.once("init", function() -box.schema.user.create('test', {password = 'test'}) -box.schema.func.create('queue.tube.test_queue:ack') -box.schema.func.create('queue.tube.test_queue:put') -box.schema.func.create('queue.tube.test_queue:drop') -box.schema.func.create('queue.tube.test_queue:peek') -box.schema.func.create('queue.tube.test_queue:kick') -box.schema.func.create('queue.tube.test_queue:take') -box.schema.func.create('queue.tube.test_queue:delete') -box.schema.func.create('queue.tube.test_queue:release') -box.schema.func.create('queue.tube.test_queue:bury') -box.schema.func.create('queue.statistics') -box.schema.user.grant('test', 'create', 'space') -box.schema.user.grant('test', 'write', 'space', '_schema') -box.schema.user.grant('test', 'write', 'space', '_space') -box.schema.user.grant('test', 'read,write', 'space', '_space_sequence') -box.schema.user.grant('test', 'write', 'space', '_index') -box.schema.user.grant('test', 'read, write', 'space', '_queue_session_ids') -box.schema.user.grant('test', 'execute', 'universe') -box.schema.user.grant('test', 'read,write', 'space', '_queue') -box.schema.user.grant('test', 'read,write', 'space', '_schema') -box.schema.user.grant('test', 'read,write', 'space', '_space') -box.schema.user.grant('test', 'read,write', 'space', '_index') -box.schema.user.grant('test', 'read,write', 'space', '_queue_consumers') -box.schema.user.grant('test', 'read,write', 'space', '_priv') -box.schema.user.grant('test', 'read,write', 'space', '_queue_taken_2') -if box.space._trigger ~= nil then - box.schema.user.grant('test', 'read', 'space', '_trigger') -end -if box.space._fk_constraint ~= nil then - box.schema.user.grant('test', 'read', 'space', '_fk_constraint') -end -if box.space._ck_constraint ~= nil then - box.schema.user.grant('test', 'read', 'space', '_ck_constraint') -end -if box.space._func_index ~= nil then - box.schema.user.grant('test', 'read', 'space', '_func_index') -end + box.once("init", function() + box.schema.user.create('test', {password = 'test'}) + box.schema.func.create('queue.tube.test_queue:ack') + box.schema.func.create('queue.tube.test_queue:put') + box.schema.func.create('queue.tube.test_queue:drop') + box.schema.func.create('queue.tube.test_queue:peek') + box.schema.func.create('queue.tube.test_queue:kick') + box.schema.func.create('queue.tube.test_queue:take') + box.schema.func.create('queue.tube.test_queue:delete') + box.schema.func.create('queue.tube.test_queue:release') + box.schema.func.create('queue.tube.test_queue:bury') + box.schema.func.create('queue.statistics') + box.schema.user.grant('test', 'create', 'space') + box.schema.user.grant('test', 'write', 'space', '_schema') + box.schema.user.grant('test', 'write', 'space', '_space') + box.schema.user.grant('test', 'read,write', 'space', '_space_sequence') + box.schema.user.grant('test', 'write', 'space', '_index') + box.schema.user.grant('test', 'read, write', 'space', '_queue_session_ids') + box.schema.user.grant('test', 'execute', 'universe') + box.schema.user.grant('test', 'read,write', 'space', '_queue') + box.schema.user.grant('test', 'read,write', 'space', '_schema') + box.schema.user.grant('test', 'read,write', 'space', '_space') + box.schema.user.grant('test', 'read,write', 'space', '_index') + box.schema.user.grant('test', 'read,write', 'space', '_queue_consumers') + box.schema.user.grant('test', 'read,write', 'space', '_priv') + box.schema.user.grant('test', 'read,write', 'space', '_queue_taken_2') + if box.space._trigger ~= nil then + box.schema.user.grant('test', 'read', 'space', '_trigger') + end + if box.space._fk_constraint ~= nil then + box.schema.user.grant('test', 'read', 'space', '_fk_constraint') + end + if box.space._ck_constraint ~= nil then + box.schema.user.grant('test', 'read', 'space', '_ck_constraint') + end + if box.space._func_index ~= nil then + box.schema.user.grant('test', 'read', 'space', '_func_index') + end end) -- Set listen only when every other thing is configured.