Skip to content

Commit

Permalink
Fluent::ConfigureProxy.new requires type_lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
okkez committed Apr 26, 2016
1 parent 12b0832 commit c6dd2d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion lib/fluent/config/configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ConfigureProxy
# end
# end

def initialize(name, param_name: nil, final: nil, init: nil, required: nil, multi: nil, alias: nil, type_lookup: nil)
def initialize(name, param_name: nil, final: nil, init: nil, required: nil, multi: nil, alias: nil, type_lookup:)
@name = name.to_sym
@final = final

Expand Down Expand Up @@ -108,6 +108,7 @@ def merge(other) # self is base class, other is subclass
options[:multi] = @multi.nil? ? other.multi : self.multi
options[:alias] = @alias.nil? ? other.alias : self.alias
options[:final] = @final || other.final
options[:type_lookup] = @type_lookup

merged = self.class.new(other.name, options)

Expand Down Expand Up @@ -166,6 +167,7 @@ def merge_for_finalized(other)
options[:multi] = @multi.nil? ? other.multi : self.multi
options[:alias] = @alias.nil? ? other.alias : self.alias
options[:final] = true
options[:type_lookup] = @type_lookup

merged = self.class.new(other.name, options)

Expand Down
24 changes: 12 additions & 12 deletions test/config/test_configure_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class TestConfigureProxy < ::Test::Unit::TestCase
sub_test_case 'to generate a instance' do
sub_test_case '#initialize' do
test 'has default values' do
proxy = Fluent::Config::ConfigureProxy.new('section')
proxy = Fluent::Config::ConfigureProxy.new('section', type_lookup: @type_lookup)
assert_equal(:section, proxy.name)

proxy = Fluent::Config::ConfigureProxy.new(:section)
proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
assert_equal(:section, proxy.name)
assert_equal(:section, proxy.param_name)
assert_nil(proxy.init)
Expand All @@ -24,15 +24,15 @@ class TestConfigureProxy < ::Test::Unit::TestCase
end

test 'can specify param_name/required/multi with optional arguments' do
proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: 'sections', init: true, required: false, multi: true)
proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: 'sections', init: true, required: false, multi: true, type_lookup: @type_lookup)
assert_equal(:section, proxy.name)
assert_equal(:sections, proxy.param_name)
assert_false(proxy.required)
assert_false(proxy.required?)
assert_true(proxy.multi)
assert_true(proxy.multi?)

proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: :sections, init: false, required: true, multi: false)
proxy = Fluent::Config::ConfigureProxy.new(:section, param_name: :sections, init: false, required: true, multi: false, type_lookup: @type_lookup)
assert_equal(:section, proxy.name)
assert_equal(:sections, proxy.param_name)
assert_true(proxy.required)
Expand All @@ -42,14 +42,14 @@ class TestConfigureProxy < ::Test::Unit::TestCase
end
test 'raise error if both of init and required are true' do
assert_raise "init and required are exclusive" do
Fluent::Config::ConfigureProxy.new(:section, init: true, required: true)
Fluent::Config::ConfigureProxy.new(:section, init: true, required: true, type_lookup: @type_lookup)
end
end
end

sub_test_case '#merge' do
test 'generate a new instance which values are overwritten by the argument object' do
proxy = p1 = Fluent::Config::ConfigureProxy.new(:section)
proxy = p1 = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
assert_equal(:section, proxy.name)
assert_equal(:section, proxy.param_name)
assert_nil(proxy.init)
Expand All @@ -59,7 +59,7 @@ class TestConfigureProxy < ::Test::Unit::TestCase
assert_true(proxy.multi?)
assert_nil(proxy.configured_in_section)

p2 = Fluent::Config::ConfigureProxy.new(:section, param_name: :sections, init: false, required: true, multi: false)
p2 = Fluent::Config::ConfigureProxy.new(:section, param_name: :sections, init: false, required: true, multi: false, type_lookup: @type_lookup)
proxy = p1.merge(p2)
assert_equal(:section, proxy.name)
assert_equal(:sections, proxy.param_name)
Expand All @@ -73,10 +73,10 @@ class TestConfigureProxy < ::Test::Unit::TestCase
end

test 'does not overwrite with argument object without any specifications of required/multi' do
p1 = Fluent::Config::ConfigureProxy.new(:section1)
p1 = Fluent::Config::ConfigureProxy.new(:section1, type_lookup: @type_lookup)
p1.configured_in_section = :subsection
p2 = Fluent::Config::ConfigureProxy.new(:section2, param_name: :sections, init: false, required: true, multi: false)
p3 = Fluent::Config::ConfigureProxy.new(:section3)
p2 = Fluent::Config::ConfigureProxy.new(:section2, param_name: :sections, init: false, required: true, multi: false, type_lookup: @type_lookup)
p3 = Fluent::Config::ConfigureProxy.new(:section3, type_lookup: @type_lookup)
proxy = p1.merge(p2).merge(p3)
assert_equal(:section3, proxy.name)
assert_equal(:section3, proxy.param_name)
Expand Down Expand Up @@ -126,13 +126,13 @@ class TestConfigureProxy < ::Test::Unit::TestCase

sub_test_case '#configured_in' do
test 'sets a section name which have configuration parameters of target plugin in owners configuration' do
proxy = Fluent::Config::ConfigureProxy.new(:section)
proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
proxy.configured_in(:mysection)
assert_equal :mysection, proxy.configured_in_section
end

test 'do not permit to be called twice' do
proxy = Fluent::Config::ConfigureProxy.new(:section)
proxy = Fluent::Config::ConfigureProxy.new(:section, type_lookup: @type_lookup)
proxy.configured_in(:mysection)
assert_raise(ArgumentError) { proxy.configured_in(:myothersection) }
end
Expand Down

0 comments on commit c6dd2d0

Please sign in to comment.