From da9ec9a05a79c19cfb21e911deb5eb92e2b4cda8 Mon Sep 17 00:00:00 2001 From: Oleg Chaplashkin Date: Fri, 26 May 2023 19:51:46 +0400 Subject: [PATCH] test: ban direct calling of box.cfg() Direct call and configuration of the runner instance is prohibited. Now if you need to test something with specific configuration use a server instance please (see luatest.Server module). In-scope-of tarantool/luatest#245 NO_DOC=ban calling box.cfg NO_TEST=ban calling box.cfg NO_CHANGELOG=ban calling box.cfg --- test/helper.lua | 19 +++++++++++++++++++ test/metrics-luatest/helper.lua | 10 +++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/helper.lua diff --git a/test/helper.lua b/test/helper.lua new file mode 100644 index 0000000000000..f4db162c784c5 --- /dev/null +++ b/test/helper.lua @@ -0,0 +1,19 @@ +-- There are situations when the Tarantool instance is configured +-- for testing. For example: +-- +-- g.test_foo = function() +-- box.cfg{params} +-- ... +-- t.assert_equals(foo, bar) +-- +-- g.test_bar = function() +-- t.assert_equals(foo, bar) +-- +-- We expect that the test environment will not be configured +-- in the `test_bar`, but this will not always be the case +-- (depends on the order of execution of tests). +-- We prohibit a direct call to `box.cfg` by overriding the +-- `__call` meta method. +box.cfg = setmetatable({}, {__call = function() + error('A direct call to `box.cfg` is not recommended' .. + ' (you are changing the test runner instance)', 0) end}) diff --git a/test/metrics-luatest/helper.lua b/test/metrics-luatest/helper.lua index ca50d593b11db..d6d6164933aa2 100644 --- a/test/metrics-luatest/helper.lua +++ b/test/metrics-luatest/helper.lua @@ -109,4 +109,12 @@ local function workaround_requires(path) end workaround_requires('test.utils') -workaround_requires('test.psutils_linux_test_payload') + +require('test.utils') +local test_root = fio.dirname( + fio.dirname(fio.abspath( + package.search('third_party.metrics.test.utils')))) -- luacheck: ignore + +package.loaded['test.utils'].LUA_PATH = os.getenv('LUA_PATH') .. + test_root .. '/?.lua;' .. + test_root .. '/?/init.lua;'