Skip to content

Commit

Permalink
Merge pull request #2003 from okkez/dump-config-argument
Browse files Browse the repository at this point in the history
Dump config_argument by dump_config_definition
  • Loading branch information
repeatedly authored May 29, 2018
2 parents ced6387 + f4be02a commit 8bc77cb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/fluent/config/configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ def config_section(name, **kwargs, &block)

def dump_config_definition
dumped_config = {}
if @argument
argument_name, _block, options = @argument
options[:required] = !@defaults.key?(argument_name)
options[:argument] = true
dumped_config[argument_name] = options
end
@params.each do |name, config|
dumped_config[name] = config[1]
dumped_config[name][:required] = !@defaults.key?(name)
Expand All @@ -378,7 +384,7 @@ def dump_config_definition
end
# Overwrite by config_set_default
@defaults.each do |name, value|
if @params.key?(name)
if @params.key?(name) || @argument.first == name
dumped_config[name][:default] = value
else
dumped_config[name] = { default: value }
Expand Down
2 changes: 1 addition & 1 deletion test/command/test_plugin_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def process(tag, es)
time_as_integer: bool: (false)
slow_flush_log_threshold: float: (20.0)
<buffer>: optional, single
chunk_keys: array: ([])
@type: string: ("memory")
timekey: time: (nil)
timekey_wait: time: (600)
Expand All @@ -154,7 +155,6 @@ def process(tag, es)
retry_exponential_backoff_base: float: (2)
retry_max_interval: time: (nil)
retry_randomize: bool: (true)
chunk_keys: : ([])
<secondary>: optional, single
@type: string: (nil)
<buffer>: optional, single
Expand Down
37 changes: 37 additions & 0 deletions test/config/test_configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,43 @@ class TestConfigureProxy < ::Test::Unit::TestCase
assert_equal(expected, @proxy.dump_config_definition)
end

test 'plain proxy w/ argument' do
@proxy.instance_eval do
config_argument(:argname, :string)
config_param(:name, :string, default: "name1")
end
expected = {
argname: { type: :string, required: true, argument: true },
name: { type: :string, default: "name1", required: false }
}
assert_equal(expected, @proxy.dump_config_definition)
end

test 'plain proxy w/ argument default value' do
@proxy.instance_eval do
config_argument(:argname, :string, default: "value")
config_param(:name, :string, default: "name1")
end
expected = {
argname: { type: :string, default: "value", required: false, argument: true },
name: { type: :string, default: "name1", required: false }
}
assert_equal(expected, @proxy.dump_config_definition)
end

test 'plain proxy w/ argument overwriting default value' do
@proxy.instance_eval do
config_argument(:argname, :string)
config_param(:name, :string, default: "name1")
config_set_default(:argname, "value1")
end
expected = {
argname: { type: :string, default: "value1", required: false, argument: true },
name: { type: :string, default: "name1", required: false }
}
assert_equal(expected, @proxy.dump_config_definition)
end

test 'single sub proxy' do
@proxy.config_section(:sub) do
config_param(:name, :string, default: "name1")
Expand Down

0 comments on commit 8bc77cb

Please sign in to comment.