Skip to content

Commit

Permalink
test: ban direct calling of box.cfg()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleg Chaplashkin committed May 31, 2023
1 parent 0ef5e3b commit da9ec9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 19 additions & 0 deletions test/helper.lua
Original file line number Diff line number Diff line change
@@ -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})
10 changes: 9 additions & 1 deletion test/metrics-luatest/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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;'

0 comments on commit da9ec9a

Please sign in to comment.