Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0: fix tests used in doc samples #3771

Merged
merged 4 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/code_snippets/test/checks/checkers_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ local is_uint64 = checkers.uint64(2048)
-- is_int64/is_uint64 = true

-- tuple checker
local is_tuple = checkers.tuple(box.tuple.new(1, 'The Beatles', 1960))
local is_tuple = checkers.tuple(box.tuple.new{1, 'The Beatles', 1960})
-- is_tuple = true

-- uuid checkers
Expand Down
10 changes: 5 additions & 5 deletions doc/code_snippets/test/constraints/constraint_sql_expr_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_constraints = function(cg)
Expand Down Expand Up @@ -42,21 +42,21 @@ g.test_constraints = function(cg)
local _, age_err = pcall(function()
-- insert_age_error_start
customers:insert { 2, "Bob", 18 }
-- error: Check constraint 'check_person' failed for tuple
-- error: Check constraint 'check_person' failed for a tuple
-- insert_age_error_end
end)

local _, name_err = pcall(function()
-- insert_name_error_start
customers:insert { 3, "Admin", 25 }
-- error: Check constraint 'check_person' failed for tuple
-- error: Check constraint 'check_person' failed for a tuple
-- insert_name_error_end
end)

-- Tests --
t.assert_equals(customers:count(), 1)
t.assert_equals(customers:get(1), { 1, "Alice", 30 })
t.assert_equals(age_err:unpack().message, 'Check constraint \'check_person\' failed for tuple')
t.assert_equals(name_err:unpack().message, 'Check constraint \'check_person\' failed for tuple')
t.assert_equals(age_err:unpack().message, 'Check constraint \'check_person\' failed for a tuple')
t.assert_equals(name_err:unpack().message, 'Check constraint \'check_person\' failed for a tuple')
end)
end
4 changes: 2 additions & 2 deletions doc/code_snippets/test/constraints/constraint_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_constraints = function(cg)
Expand Down Expand Up @@ -51,7 +51,7 @@ g.test_constraints = function(cg)
t.assert_equals(customers:get(1), {1, "Alice", 30})

-- Failed contstraint --
t.assert_error_msg_contains("Check constraint 'check_person' failed for tuple",
t.assert_error_msg_contains("Check constraint 'check_person' failed for a tuple",
function() customers:insert{2, "Bob", 230} end)

-- Create one more tuple constraint --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_foreign_keys = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_foreign_keys = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_indexes = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_func_multikey_index = function(cg)
Expand Down
2 changes: 1 addition & 1 deletion doc/code_snippets/test/indexes/create_index_func_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_func_index = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_json_path_index = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_indexes = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_indexes = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_indexes = function(cg)
Expand Down
2 changes: 1 addition & 1 deletion doc/code_snippets/test/indexes/index_select_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_indexes = function(cg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

local function find_in_log(cg, str, must_be_present)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

local function find_in_log(cg, str, must_be_present)
Expand Down
2 changes: 1 addition & 1 deletion doc/code_snippets/test/logging/log_new_modules_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

local function find_in_log(cg, str, must_be_present)
Expand Down
2 changes: 1 addition & 1 deletion doc/code_snippets/test/logging/log_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

local function find_in_log(cg, str, must_be_present)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local msgpack = require('msgpack')

local mp_from_array = msgpack.object({ 10, 20, 30 })
local mp_from_table = msgpack.object({ band_name = 'The Beatles', year = 1960 })
local mp_from_tuple = msgpack.object(box.tuple.new(1, 'The Beatles', 1960))
local mp_from_tuple = msgpack.object(box.tuple.new{1, 'The Beatles', 1960})

-- Get MsgPack data by the specified index or key
local mp_array_get_by_index = mp_from_array[1] -- Returns 10
Expand Down
2 changes: 1 addition & 1 deletion doc/code_snippets/test/msgpack/msgpack_object_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local mp_from_number = msgpack.object(123)
local mp_from_string = msgpack.object('hello world')
local mp_from_array = msgpack.object({ 10, 20, 30 })
local mp_from_table = msgpack.object({ band_name = 'The Beatles', year = 1960 })
local mp_from_tuple = msgpack.object(box.tuple.new(1, 'The Beatles', 1960))
local mp_from_tuple = msgpack.object(box.tuple.new{1, 'The Beatles', 1960})

-- Create a MsgPack object from a raw MsgPack string
local raw_mp_string = msgpack.encode({ 10, 20, 30 })
Expand Down
2 changes: 1 addition & 1 deletion doc/code_snippets/test/sequence/sequence_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_sequence = function(cg)
Expand Down
2 changes: 1 addition & 1 deletion doc/code_snippets/test/sql/array_access_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_space_is_updated = function(cg)
Expand Down
6 changes: 3 additions & 3 deletions doc/code_snippets/test/sql/check_table_constraint_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_space_is_updated = function(cg)
Expand All @@ -36,12 +36,12 @@ g.test_space_is_updated = function(cg)
-- insert_short_name_start
INSERT INTO author VALUES (3, 'Alex');
/*
- Check constraint 'CHECK_NAME_LENGTH' failed for tuple
- Check constraint 'check_name_length' failed for a tuple
*/
-- insert_short_name_end
]])

-- Tests
t.assert_equals(insert_author_err:unpack().message, "Check constraint 'CHECK_NAME_LENGTH' failed for tuple")
t.assert_equals(insert_author_err:unpack().message, "Check constraint 'check_name_length' failed for a tuple")
end)
end
14 changes: 7 additions & 7 deletions doc/code_snippets/test/sql/foreign_key_table_constraint_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_space_is_updated = function(cg)
Expand Down Expand Up @@ -53,30 +53,30 @@ g.test_space_is_updated = function(cg)
-- insert_error_start
INSERT INTO book VALUES (3, 'Eugene Onegin', 3);
/*
- 'Foreign key constraint ''fk_unnamed_BOOK_1'' failed: foreign tuple was not found'
- 'Foreign key constraint ''fk_unnamed_book_1'' failed: foreign tuple was not found'
*/
-- insert_error_end
]])
local _, update_err = box.execute([[
-- update_error_start
UPDATE book SET author_id = 10 WHERE id = 1;
/*
- 'Foreign key constraint ''fk_unnamed_BOOK_1'' failed: foreign tuple was not found'
- 'Foreign key constraint ''fk_unnamed_book_1'' failed: foreign tuple was not found'
*/
-- update_error_end
]])
local _, delete_err = box.execute([[
-- delete_error_start
DELETE FROM author WHERE id = 2;
/*
- 'Foreign key ''fk_unnamed_BOOK_1'' integrity check failed: tuple is referenced'
- 'Foreign key ''fk_unnamed_book_1'' integrity check failed: tuple is referenced'
*/
-- delete_error_end
]])

-- Tests
t.assert_equals(insert_err:unpack().message, "Foreign key constraint 'fk_unnamed_BOOK_1' failed: foreign tuple was not found")
t.assert_equals(update_err:unpack().message, "Foreign key constraint 'fk_unnamed_BOOK_1' failed: foreign tuple was not found")
t.assert_equals(delete_err:unpack().message, "Foreign key 'fk_unnamed_BOOK_1' integrity check failed: tuple is referenced")
t.assert_equals(insert_err:unpack().message, "Foreign key constraint 'fk_unnamed_book_1' failed: foreign tuple was not found")
t.assert_equals(update_err:unpack().message, "Foreign key constraint 'fk_unnamed_book_1' failed: foreign tuple was not found")
t.assert_equals(delete_err:unpack().message, "Foreign key 'fk_unnamed_book_1' integrity check failed: tuple is referenced")
end)
end
2 changes: 1 addition & 1 deletion doc/code_snippets/test/sql/map_access_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_space_is_updated = function(cg)
Expand Down
10 changes: 5 additions & 5 deletions doc/code_snippets/test/sql/primary_key_table_constraint_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_space_is_updated = function(cg)
Expand All @@ -35,7 +35,7 @@ g.test_space_is_updated = function(cg)
-- insert_duplicate_author_start
INSERT INTO author VALUES (2, 'Alexander Pushkin');
/*
- Duplicate key exists in unique index "pk_unnamed_AUTHOR_1" in space "AUTHOR" with
- Duplicate key exists in unique index "pk_unnamed_author_1" in space "author" with
old tuple - [2, "Fyodor Dostoevsky"] and new tuple - [2, "Alexander Pushkin"]
*/
-- insert_duplicate_author_end
Expand All @@ -59,14 +59,14 @@ g.test_space_is_updated = function(cg)
-- insert_duplicate_book_start
INSERT INTO book VALUES (2, 'Crime and Punishment');
/*
- Duplicate key exists in unique index "pk_unnamed_BOOK_1" in space "BOOK" with old
- Duplicate key exists in unique index "pk_unnamed_book_1" in space "BOOK" with old
tuple - [2, "Crime and Punishment"] and new tuple - [2, "Crime and Punishment"]
*/
-- insert_duplicate__book_end
]])

-- Tests
t.assert_equals(insert_author_err:unpack().message, "Duplicate key exists in unique index \"pk_unnamed_AUTHOR_1\" in space \"AUTHOR\" with old tuple - [2, \"Fyodor Dostoevsky\"] and new tuple - [2, \"Alexander Pushkin\"]")
t.assert_equals(insert_book_err:unpack().message, "Duplicate key exists in unique index \"pk_unnamed_BOOK_1\" in space \"BOOK\" with old tuple - [2, \"Crime and Punishment\"] and new tuple - [2, \"Crime and Punishment\"]")
t.assert_equals(insert_author_err:unpack().message, "Duplicate key exists in unique index \"pk_unnamed_author_1\" in space \"author\" with old tuple - [2, \"Fyodor Dostoevsky\"] and new tuple - [2, \"Alexander Pushkin\"]")
t.assert_equals(insert_book_err:unpack().message, "Duplicate key exists in unique index \"pk_unnamed_book_1\" in space \"book\" with old tuple - [2, \"Crime and Punishment\"] and new tuple - [2, \"Crime and Punishment\"]")
end)
end
10 changes: 5 additions & 5 deletions doc/code_snippets/test/sql/unique_table_constraint_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ g.before_each(function(cg)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
fio.rmtree(cg.server.workdir)
end)

g.test_space_is_updated = function(cg)
Expand All @@ -35,7 +35,7 @@ g.test_space_is_updated = function(cg)
-- insert_duplicate_author_start
INSERT INTO author VALUES (3, 'Leo Tolstoy');
/*
- Duplicate key exists in unique index "unique_unnamed_AUTHOR_2" in space "AUTHOR"
- Duplicate key exists in unique index "unique_unnamed_author_2" in space "author"
with old tuple - [1, "Leo Tolstoy"] and new tuple - [3, "Leo Tolstoy"]
*/
-- insert_duplicate_author_end
Expand All @@ -60,14 +60,14 @@ g.test_space_is_updated = function(cg)
-- insert_duplicate_book_start
INSERT INTO book VALUES (3, 'War and Peace', 1);
/*
- Duplicate key exists in unique index "unique_unnamed_BOOK_2" in space "BOOK" with
- Duplicate key exists in unique index "unique_unnamed_book_2" in space "book" with
old tuple - [1, "War and Peace", 1] and new tuple - [3, "War and Peace", 1]
*/
-- insert_duplicate__book_end
]])

-- Tests
t.assert_equals(insert_author_err:unpack().message, "Duplicate key exists in unique index \"unique_unnamed_AUTHOR_2\" in space \"AUTHOR\" with old tuple - [1, \"Leo Tolstoy\"] and new tuple - [3, \"Leo Tolstoy\"]")
t.assert_equals(insert_book_err:unpack().message, "Duplicate key exists in unique index \"unique_unnamed_BOOK_2\" in space \"BOOK\" with old tuple - [1, \"War and Peace\", 1] and new tuple - [3, \"War and Peace\", 1]")
t.assert_equals(insert_author_err:unpack().message, "Duplicate key exists in unique index \"unique_unnamed_author_2\" in space \"author\" with old tuple - [1, \"Leo Tolstoy\"] and new tuple - [3, \"Leo Tolstoy\"]")
t.assert_equals(insert_book_err:unpack().message, "Duplicate key exists in unique index \"unique_unnamed_book_2\" in space \"book\" with old tuple - [1, \"War and Peace\", 1] and new tuple - [3, \"War and Peace\", 1]")
end)
end
Loading