forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 58
/
config.lua
295 lines (259 loc) · 8.34 KB
/
config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
-- Do not set listen for now so connector won't be
-- able to send requests until everything is configured.
local auth_type = os.getenv("TEST_TNT_AUTH_TYPE")
if auth_type == "auto" then
auth_type = nil
end
box.cfg{
auth_type = auth_type,
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
memtx_use_mvcc_engine = os.getenv("TEST_TNT_MEMTX_USE_MVCC_ENGINE") == 'true' or nil,
}
box.once("init", function()
local st = box.schema.space.create('schematest', {
id = 616,
temporary = true,
if_not_exists = true,
field_count = 8,
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"},
{name = "nullable", is_nullable = true},
},
})
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 s = box.schema.space.create('test', {
id = 617,
if_not_exists = true,
})
s:create_index('primary', {
type = 'tree',
parts = {1, 'uint'},
if_not_exists = true
})
local s = box.schema.space.create('teststring', {
id = 618,
if_not_exists = true,
})
s:create_index('primary', {
type = 'tree',
parts = {1, 'string'},
if_not_exists = true
})
local s = box.schema.space.create('testintint', {
id = 619,
if_not_exists = true,
})
s:create_index('primary', {
type = 'tree',
parts = {1, 'int', 2, 'int'},
if_not_exists = true
})
local s = box.schema.space.create('SQL_TEST', {
id = 620,
if_not_exists = true,
format = {
{name = "NAME0", type = "unsigned"},
{name = "NAME1", type = "string"},
{name = "NAME2", type = "string"},
}
})
s:create_index('primary', {
type = 'tree',
parts = {1, 'uint'},
if_not_exists = true
})
s:insert{1, "test", "test"}
local s = box.schema.space.create('test_perf', {
id = 621,
temporary = true,
if_not_exists = true,
field_count = 3,
format = {
{name = "id", type = "unsigned"},
{name = "name", type = "string"},
{name = "arr1", type = "array"},
},
})
s:create_index('primary', {
type = 'tree',
unique = true,
parts = {1, 'unsigned'},
if_not_exists = true
})
s:create_index('secondary', {
id = 5, type = 'tree',
unique = false,
parts = {2, 'string'},
if_not_exists = true
})
local arr_data = {}
for i = 1,100 do
arr_data[i] = i
end
for i = 1,1000 do
s:insert{
i,
'test_name',
arr_data,
}
end
local s = box.schema.space.create('test_error_type', {
id = 622,
temporary = true,
if_not_exists = true,
field_count = 2,
-- You can't specify box.error as format type,
-- but can put box.error objects.
})
s:create_index('primary', {
type = 'tree',
unique = true,
parts = {1, 'string'},
if_not_exists = true
})
--box.schema.user.grant('guest', 'read,write,execute', 'universe')
box.schema.func.create('box.info')
box.schema.func.create('simple_concat')
-- 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')
box.schema.user.grant('test', 'read,write', 'space', 'test_perf')
box.schema.user.grant('test', 'read,write', 'space', 'test_error_type')
-- grants for sql tests
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space')
box.schema.user.grant('test', 'create', 'sequence')
box.schema.user.create('no_grants')
end)
local function func_name()
return {
{221, "", {
{"Moscow", 34},
{"Minsk", 23},
{"Kiev", 31},
}
}
}
end
rawset(_G, 'func_name', func_name)
local function simple_concat(a)
return a .. a
end
rawset(_G, 'simple_concat', simple_concat)
local function push_func(cnt)
for i = 1, cnt do
box.session.push(i)
end
return cnt
end
rawset(_G, 'push_func', push_func)
local function create_spaces()
for i=1,10 do
local s = box.schema.space.create('test' .. tostring(i), {
id = 700 + i,
if_not_exists = true,
})
local idx = s:create_index('test' .. tostring(i) .. 'primary', {
type = 'tree',
parts = {1, 'uint'},
if_not_exists = true
})
idx:drop()
s:drop()
end
end
rawset(_G, 'create_spaces', create_spaces)
local function tarantool_version_at_least(wanted_major, wanted_minor, wanted_patch)
-- https://github.com/tarantool/crud/blob/733528be02c1ffa3dacc12c034ee58c9903127fc/test/helper.lua#L316-L337
local major_minor_patch = _TARANTOOL:split('-', 1)[1]
local major_minor_patch_parts = major_minor_patch:split('.', 2)
local major = tonumber(major_minor_patch_parts[1])
local minor = tonumber(major_minor_patch_parts[2])
local patch = tonumber(major_minor_patch_parts[3])
if major < (wanted_major or 0) then return false end
if major > (wanted_major or 0) then return true end
if minor < (wanted_minor or 0) then return false end
if minor > (wanted_minor or 0) then return true end
if patch < (wanted_patch or 0) then return false end
if patch > (wanted_patch or 0) then return true end
return true
end
if tarantool_version_at_least(2, 4, 1) then
local e1 = box.error.new(box.error.UNKNOWN)
rawset(_G, 'simple_error', e1)
local e2 = box.error.new(box.error.TIMEOUT)
e2:set_prev(e1)
rawset(_G, 'chained_error', e2)
local user = box.session.user()
box.schema.func.create('forbidden_function', {body = 'function() end'})
box.session.su('no_grants')
local _, access_denied_error = pcall(function() box.func.forbidden_function:call() end)
box.session.su(user)
rawset(_G, 'access_denied_error', access_denied_error)
-- cdata structure is as follows:
--
-- tarantool> err:unpack()
-- - code: val
-- base_type: val
-- type: val
-- message: val
-- field1: val
-- field2: val
-- trace:
-- - file: val
-- line: val
local function compare_box_error_attributes(expected, actual)
for attr, _ in pairs(expected:unpack()) do
if (attr ~= 'prev') and (attr ~= 'trace') then
if expected[attr] ~= actual[attr] then
error(('%s expected %s is not equal to actual %s'):format(
attr, expected[attr], actual[attr]))
end
end
end
end
local function compare_box_errors(expected, actual)
if (expected == nil) and (actual ~= nil) then
error(('Expected error stack is empty, but actual error ' ..
'has previous %s (%s) error'):format(
actual.type, actual.message))
end
if (expected ~= nil) and (actual == nil) then
error(('Actual error stack is empty, but expected error ' ..
'has previous %s (%s) error'):format(
expected.type, expected.message))
end
compare_box_error_attributes(expected, actual)
if (expected.prev ~= nil) or (actual.prev ~= nil) then
return compare_box_errors(expected.prev, actual.prev)
end
return true
end
rawset(_G, 'compare_box_errors', compare_box_errors)
end
box.space.test:truncate()
--box.schema.user.revoke('guest', 'read,write,execute', 'universe')
-- Set listen only when every other thing is configured.
box.cfg{
auth_type = auth_type,
listen = os.getenv("TEST_TNT_LISTEN"),
}