Skip to content

Commit 4f0fbd1

Browse files
committed
test: define test space format once
Now every test file defines it's own test space format. However all these formats are similar and we can define once in helpers to avoid code duplication.
1 parent 17804f8 commit 4f0fbd1

File tree

6 files changed

+60
-124
lines changed

6 files changed

+60
-124
lines changed

test/bucket_id_test.lua

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,6 @@ local helper = require('test.helper')
99
local REFERENCE_KEY = {1, 2, 3}
1010
local REFERENCE_BUCKET_ID = 4018458701
1111

12-
local test_space = {
13-
engine = 'memtx',
14-
is_local = true,
15-
temporary = false,
16-
format = {
17-
{name = 'unsigned_nonnull', type = 'unsigned', is_nullable = false},
18-
{name = 'unsigned_nullable', type = 'unsigned', is_nullable = true},
19-
{name = 'integer_nonnull', type = 'integer', is_nullable = false},
20-
{name = 'integer_nullable', type = 'integer', is_nullable = true},
21-
{name = 'number_nonnull', type = 'number', is_nullable = false},
22-
{name = 'number_nullable', type = 'number', is_nullable = true},
23-
{name = 'boolean_nonnull', type = 'boolean', is_nullable = false},
24-
{name = 'boolean_nullable', type = 'boolean', is_nullable = true},
25-
{name = 'string_nonnull', type = 'string', is_nullable = false},
26-
{name = 'string_nullable', type = 'string', is_nullable = true},
27-
{name = 'scalar_nonnull', type = 'scalar', is_nullable = false},
28-
{name = 'scalar_nullable', type = 'scalar', is_nullable = true},
29-
{name = 'array_nonnull', type = 'array', is_nullable = false},
30-
{name = 'array_nullable', type = 'array', is_nullable = true},
31-
{name = 'map_nonnull', type = 'map', is_nullable = false},
32-
{name = 'map_nullable', type = 'map', is_nullable = true},
33-
{name = 'any_nonnull', type = 'any', is_nullable = false},
34-
{name = 'any_nullable', type = 'any', is_nullable = true},
35-
},
36-
}
37-
3812
local primary_index = {
3913
type = 'HASH',
4014
unique = true,
@@ -57,7 +31,13 @@ g.before_all(db.init)
5731
g.before_each(function()
5832
db.drop_all()
5933

60-
g.space = table.deepcopy(test_space)
34+
g.space = {
35+
engine = 'memtx',
36+
is_local = true,
37+
temporary = false,
38+
format = table.deepcopy(helper.test_space_format())
39+
}
40+
6141
table.insert(g.space.format, 1, {
6242
name = 'bucket_id', type = 'unsigned', is_nullable = false
6343
})

test/check_schema_test.lua

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,28 @@ local db = require('test.db')
55
local ddl_check = require('ddl.check')
66
local ddl = require('ddl')
77

8+
local helper = require('test.helper')
9+
810
local g = t.group()
911
g.before_all(db.init)
1012
g.before_each(db.drop_all)
1113

14+
local space_format = helper.test_space_format()
15+
table.insert(space_format, {name = 'decimal_nonnull', type = 'decimal', is_nullable = false})
16+
table.insert(space_format, {name = 'decimal_null', type = 'decimal', is_nullable = true})
17+
table.insert(space_format, {name = 'double_nonnull', type = 'double', is_nullable = false})
18+
table.insert(space_format, {name = 'double_null', type = 'double', is_nullable = true})
19+
table.insert(space_format, {name = 'uuid_nonnull', type = 'uuid', is_nullable = false})
20+
table.insert(space_format, {name = 'uuid_null', type = 'uuid', is_nullable = true})
21+
table.insert(space_format, {name = 'annotated', type = 'any', is_nullable = true, comment = 'x'})
22+
1223
local test_space = {
1324
engine = 'memtx',
1425
is_local = true,
1526
temporary = false,
16-
format = {
17-
{name = 'unsigned_nonnull', type = 'unsigned', is_nullable = false},
18-
{name = 'unsigned_nullable', type = 'unsigned', is_nullable = true},
19-
{name = 'integer_nonnull', type = 'integer', is_nullable = false},
20-
{name = 'integer_nullable', type = 'integer', is_nullable = true},
21-
{name = 'number_nonnull', type = 'number', is_nullable = false},
22-
{name = 'number_nullable', type = 'number', is_nullable = true},
23-
{name = 'boolean_nonnull', type = 'boolean', is_nullable = false},
24-
{name = 'boolean_nullable', type = 'boolean', is_nullable = true},
25-
{name = 'string_nonnull', type = 'string', is_nullable = false},
26-
{name = 'string_nullable', type = 'string', is_nullable = true},
27-
{name = 'scalar_nonnull', type = 'scalar', is_nullable = false},
28-
{name = 'scalar_nullable', type = 'scalar', is_nullable = true},
29-
{name = 'array_nonnull', type = 'array', is_nullable = false},
30-
{name = 'array_nullable', type = 'array', is_nullable = true},
31-
{name = 'map_nonnull', type = 'map', is_nullable = false},
32-
{name = 'map_nullable', type = 'map', is_nullable = true},
33-
{name = 'any_nonnull', type = 'any', is_nullable = false},
34-
{name = 'any_nullable', type = 'any', is_nullable = true},
35-
---------------------------------------------------------
36-
{name = 'decimal_nonnull', type = 'decimal', is_nullable = false},
37-
{name = 'decimal_null', type = 'decimal', is_nullable = true},
38-
{name = 'double_nonnull', type = 'double', is_nullable = false},
39-
{name = 'double_null', type = 'double', is_nullable = true},
40-
{name = 'uuid_nonnull', type = 'uuid', is_nullable = false},
41-
{name = 'uuid_null', type = 'uuid', is_nullable = true},
42-
43-
{name = 'annotated', type = 'any', is_nullable = true, comment = 'x'},
44-
},
27+
format = space_format
4528
}
4629

47-
4830
local test_indexes = {{
4931
type = 'HASH',
5032
unique = true,

test/check_sharding_metadata_test.lua

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,14 @@ local db = require('test.db')
55
local ddl = require('ddl')
66
local ffi = require('ffi')
77

8+
local helper = require('test.helper')
9+
810
local g = t.group()
911
local test_space = {
1012
engine = 'memtx',
1113
is_local = true,
1214
temporary = false,
13-
format = {
14-
{name = 'unsigned_nonnull', type = 'unsigned', is_nullable = false},
15-
{name = 'unsigned_nullable', type = 'unsigned', is_nullable = true},
16-
{name = 'integer_nonnull', type = 'integer', is_nullable = false},
17-
{name = 'integer_nullable', type = 'integer', is_nullable = true},
18-
{name = 'number_nonnull', type = 'number', is_nullable = false},
19-
{name = 'number_nullable', type = 'number', is_nullable = true},
20-
{name = 'boolean_nonnull', type = 'boolean', is_nullable = false},
21-
{name = 'boolean_nullable', type = 'boolean', is_nullable = true},
22-
{name = 'string_nonnull', type = 'string', is_nullable = false},
23-
{name = 'string_nullable', type = 'string', is_nullable = true},
24-
{name = 'scalar_nonnull', type = 'scalar', is_nullable = false},
25-
{name = 'scalar_nullable', type = 'scalar', is_nullable = true},
26-
{name = 'array_nonnull', type = 'array', is_nullable = false},
27-
{name = 'array_nullable', type = 'array', is_nullable = true},
28-
{name = 'map_nonnull', type = 'map', is_nullable = false},
29-
{name = 'map_nullable', type = 'map', is_nullable = true},
30-
{name = 'any_nonnull', type = 'any', is_nullable = false},
31-
{name = 'any_nullable', type = 'any', is_nullable = true},
32-
},
15+
format = helper.test_space_format(),
3316
}
3417

3518
local primary_index = {

test/helper.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require('strict').on()
22

3+
local db = require('test.db')
4+
35
local fio = require('fio')
46
local digest = require('digest')
57
local helpers = table.copy(require('luatest').helpers)
@@ -20,6 +22,36 @@ fio.tempdir = function(base)
2022
end
2123
end
2224

25+
function helpers.test_space_format()
26+
local space_format = {
27+
{name = 'unsigned_nonnull', type = 'unsigned', is_nullable = false},
28+
{name = 'unsigned_nullable', type = 'unsigned', is_nullable = true},
29+
{name = 'integer_nonnull', type = 'integer', is_nullable = false},
30+
{name = 'integer_nullable', type = 'integer', is_nullable = true},
31+
{name = 'number_nonnull', type = 'number', is_nullable = false},
32+
{name = 'number_nullable', type = 'number', is_nullable = true},
33+
{name = 'boolean_nonnull', type = 'boolean', is_nullable = false},
34+
{name = 'boolean_nullable', type = 'boolean', is_nullable = true},
35+
{name = 'string_nonnull', type = 'string', is_nullable = false},
36+
{name = 'string_nullable', type = 'string', is_nullable = true},
37+
{name = 'scalar_nonnull', type = 'scalar', is_nullable = false},
38+
{name = 'scalar_nullable', type = 'scalar', is_nullable = true},
39+
{name = 'array_nonnull', type = 'array', is_nullable = false},
40+
{name = 'array_nullable', type = 'array', is_nullable = true},
41+
{name = 'map_nonnull', type = 'map', is_nullable = false},
42+
{name = 'map_nullable', type = 'map', is_nullable = true},
43+
{name = 'any_nonnull', type = 'any', is_nullable = false},
44+
{name = 'any_nullable', type = 'any', is_nullable = true},
45+
}
46+
47+
if db.v(2, 2) then
48+
table.insert(space_format, {name = 'varbinary_nonnull', type = 'varbinary', is_nullable = false})
49+
table.insert(space_format, {name = 'varbinary_nullable', type = 'varbinary', is_nullable = true})
50+
end
51+
52+
return table.deepcopy(space_format)
53+
end
54+
2355
function helpers.entrypoint(name)
2456
local path = fio.pathjoin(
2557
helpers.project_root,

test/set_schema_test.lua

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,14 @@ local db = require('test.db')
55
local ddl = require('ddl')
66
local log = require('log')
77

8+
local helper = require('test.helper')
9+
810
local g = t.group()
911
g.before_all(db.init)
1012
g.before_each(db.drop_all)
1113

1214
local function init_test_data()
13-
local space_format = {
14-
{name = 'unsigned_nonnull', type = 'unsigned', is_nullable = false},
15-
{name = 'unsigned_nullable', type = 'unsigned', is_nullable = true},
16-
{name = 'integer_nonnull', type = 'integer', is_nullable = false},
17-
{name = 'integer_nullable', type = 'integer', is_nullable = true},
18-
{name = 'number_nonnull', type = 'number', is_nullable = false},
19-
{name = 'number_nullable', type = 'number', is_nullable = true},
20-
{name = 'boolean_nonnull', type = 'boolean', is_nullable = false},
21-
{name = 'boolean_nullable', type = 'boolean', is_nullable = true},
22-
{name = 'string_nonnull', type = 'string', is_nullable = false},
23-
{name = 'string_nullable', type = 'string', is_nullable = true},
24-
{name = 'scalar_nonnull', type = 'scalar', is_nullable = false},
25-
{name = 'scalar_nullable', type = 'scalar', is_nullable = true},
26-
{name = 'array_nonnull', type = 'array', is_nullable = false},
27-
{name = 'array_nullable', type = 'array', is_nullable = true},
28-
{name = 'map_nonnull', type = 'map', is_nullable = false},
29-
{name = 'map_nullable', type = 'map', is_nullable = true},
30-
{name = 'any_nonnull', type = 'any', is_nullable = false},
31-
{name = 'any_nullable', type = 'any', is_nullable = true},
32-
{name = 'varbinary_nonnull', type = 'varbinary', is_nullable = false},
33-
{name = 'varbinary_nullable', type = 'varbinary', is_nullable = true},
34-
}
35-
36-
if not db.v(2, 2) then
37-
space_format[19] = nil
38-
space_format[20] = nil
39-
end
15+
local space_format = helper.test_space_format()
4016

4117
return {
4218
['test'] = {

test/set_sharding_metadata_test.lua

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,14 @@ local db = require('test.db')
55
local ddl = require('ddl')
66
local ffi = require('ffi')
77

8+
local helper = require('test.helper')
9+
810
local g = t.group()
911
local test_space = {
1012
engine = 'memtx',
1113
is_local = true,
1214
temporary = false,
13-
format = {
14-
{name = 'unsigned_nonnull', type = 'unsigned', is_nullable = false},
15-
{name = 'unsigned_nullable', type = 'unsigned', is_nullable = true},
16-
{name = 'integer_nonnull', type = 'integer', is_nullable = false},
17-
{name = 'integer_nullable', type = 'integer', is_nullable = true},
18-
{name = 'number_nonnull', type = 'number', is_nullable = false},
19-
{name = 'number_nullable', type = 'number', is_nullable = true},
20-
{name = 'boolean_nonnull', type = 'boolean', is_nullable = false},
21-
{name = 'boolean_nullable', type = 'boolean', is_nullable = true},
22-
{name = 'string_nonnull', type = 'string', is_nullable = false},
23-
{name = 'string_nullable', type = 'string', is_nullable = true},
24-
{name = 'scalar_nonnull', type = 'scalar', is_nullable = false},
25-
{name = 'scalar_nullable', type = 'scalar', is_nullable = true},
26-
{name = 'array_nonnull', type = 'array', is_nullable = false},
27-
{name = 'array_nullable', type = 'array', is_nullable = true},
28-
{name = 'map_nonnull', type = 'map', is_nullable = false},
29-
{name = 'map_nullable', type = 'map', is_nullable = true},
30-
{name = 'any_nonnull', type = 'any', is_nullable = false},
31-
{name = 'any_nullable', type = 'any', is_nullable = true},
32-
},
15+
format = helper.test_space_format(),
3316
}
3417

3518
local primary_index = {

0 commit comments

Comments
 (0)