Skip to content
Snippets Groups Projects
Commit 9b289de1 authored by Alexander Turenko's avatar Alexander Turenko Committed by Alexander Turenko
Browse files

config: allow to extend the module on Tarantool CE

Part of #8862

NO_DOC=this API is not marked as public, at least now
parent 902919ca
No related branches found
No related tags found
No related merge requests found
## feature/config
* Introduced a non-public API for extending the declarative config
functionality in Tarantool Community Edition (gh-8862).
......@@ -5,11 +5,37 @@ local log = require('internal.config.utils.log')
local tarantool = require('tarantool')
local datetime = require('datetime')
local extras = nil
if tarantool.package == 'Tarantool Enterprise' then
extras = require('internal.config.extras')
-- Tarantool Enterprise Edition has its own additions
-- for config module.
--
-- Tarantool Community Edition may be extended using the same
-- mechanism.
local function load_extras()
local has_extras, extras = pcall(require, 'internal.config.extras')
-- The module is built into Tarantool EE executable. If it
-- can't be loaded, something is definitely going wrong.
if not has_extras and tarantool.package == 'Tarantool Enterprise' then
error('Tarantool Enterprise Edition build seems broken: built-in ' ..
'module internal.config.extras is not found')
end
-- The module may be provided by a user for Tarantool CE, but
-- it is optional.
if not has_extras then
return
end
-- Verify the contract.
assert(type(extras) == 'table')
assert(type(extras.initialize) == 'function')
assert(type(extras.post_apply) == 'function')
return extras
end
local extras = load_extras()
-- {{{ Helpers
-- Remove indent from a text.
......@@ -125,8 +151,6 @@ function methods._initialize(self)
self:_register_applier(require('internal.config.applier.fiber'))
self:_register_applier(require('internal.config.applier.app'))
-- Tarantool Enterprise Edition has its own additions
-- for this module.
if extras ~= nil then
extras.initialize(self)
end
......
......@@ -453,3 +453,68 @@ for case_name, case in pairs({
end
end
end
-- Verify that it is possible to extend config's functionality
-- using a non-public API.
--
-- The test registers an additional configuration source and
-- verifies that values from it are taken into account.
--
-- It also verifies that the extension can add a post-apply hook.
g.test_extras_on_community_edition = function(g)
-- Tarantool EE has its own internal.config.extras module, so
-- the external one will be ignored (if it is not placed into
-- the `override` directory).
t.tarantool.skip_if_enterprise()
local extras = string.dump(function()
local mysource = setmetatable({
name = 'mysource',
type = 'instance',
_values = {},
}, {
__index = {
sync = function(self, _config, _iconfig)
self._values = {
fiber = {
slice = {
warn = 10,
err = 15,
},
},
}
end,
get = function(self)
return self._values
end,
},
})
local function initialize(config)
config:_register_source(mysource)
end
local function post_apply(_config)
rawset(_G, 'foo', 'extras.post_apply() is called')
end
return {
initialize = initialize,
post_apply = post_apply,
}
end)
local dir = treegen.prepare_directory(g, {}, {})
treegen.write_script(dir, 'internal/config/extras.lua', extras)
local verify = function()
local config = require('config')
t.assert_equals(config:get('fiber.slice'), {warn = 10, err = 15})
t.assert_equals(rawget(_G, 'foo'), 'extras.post_apply() is called')
end
helpers.success_case(g, {
dir = dir,
verify = verify,
})
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment