Skip to content

Commit

Permalink
Use data in tests
Browse files Browse the repository at this point in the history
Signed-off-by: abetomo <[email protected]>
  • Loading branch information
abetomo committed Mar 10, 2023
1 parent 74c0a86 commit d691d6f
Showing 1 changed file with 72 additions and 104 deletions.
176 changes: 72 additions & 104 deletions test/plugin/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,125 +154,93 @@ class FluentPluginBaseTest::DummyPlugin2 < Fluent::Plugin::TestBase
end

sub_test_case 'system_config.workers value after configure' do
def assert_system_config_workers_value(data)
conf = config_element()
conf.set_target_worker_ids(data[:target_worker_ids])
@p.configure(conf)
assert{ @p.system_config.workers == data[:expected] }
end

def stub_supervisor_mode
stub(Fluent::Engine).supervisor_mode { true }
stub(Fluent::Engine).worker_id { -1 }
end

sub_test_case 'with <system> workers 3 </system>' do
setup do
system_config = Fluent::SystemConfig.new
system_config.workers = 3
stub(Fluent::Engine).system_config { system_config }
end

sub_test_case 'supervisor_mode is true' do
setup do
stub(Fluent::Engine).supervisor_mode { true }
stub(Fluent::Engine).worker_id { -1 }
end

test 'without <worker> directive' do
conf = config_element()
conf.set_target_worker_ids([])
@p.configure(conf)
assert{ @p.system_config.workers == 3 }
end

test 'with <worker 0>' do
conf = config_element()
conf.set_target_worker_ids([0])
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end

test 'with <worker 0-1>' do
conf = config_element()
conf.set_target_worker_ids([0, 1])
@p.configure(conf)
assert{ @p.system_config.workers == 2 }
end

test 'with <worker 0-2>' do
conf = config_element()
conf.set_target_worker_ids([0, 1, 2])
@p.configure(conf)
assert{ @p.system_config.workers == 3 }
end
data(
'without <worker> directive',
{
target_worker_ids: [],
expected: 3
},
keep: true
)
data(
'with <worker 0>',
{
target_worker_ids: [0],
expected: 1
},
keep: true
)
data(
'with <worker 0-1>',
{
target_worker_ids: [0, 1],
expected: 2
},
keep: true
)
data(
'with <worker 0-2>',
{
target_worker_ids: [0, 1, 2],
expected: 3
},
keep: true
)

test 'system_config.workers value after configure' do
assert_system_config_workers_value(data)
end

sub_test_case 'supervisor_mode is false' do
setup do
stub(Fluent::Engine).supervisor_mode { false }
stub(Fluent::Engine).worker_id { 0 }
end

test 'without <worker> directive' do
conf = config_element()
conf.set_target_worker_ids([])
@p.configure(conf)
assert{ @p.system_config.workers == 3 }
end

test 'with <worker 0>' do
conf = config_element()
conf.set_target_worker_ids([0])
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end

test 'with <worker 0-1>' do
conf = config_element()
conf.set_target_worker_ids([0, 1])
@p.configure(conf)
assert{ @p.system_config.workers == 2 }
end

test 'with <worker 0-2>' do
conf = config_element()
conf.set_target_worker_ids([0, 1, 2])
@p.configure(conf)
assert{ @p.system_config.workers == 3 }
end
test 'system_config.workers value after configure with supervisor_mode' do
stub_supervisor_mode
assert_system_config_workers_value(data)
end
end

sub_test_case 'without <system> directive' do
sub_test_case 'supervisor_mode is true' do
setup do
stub(Fluent::Engine).supervisor_mode { true }
stub(Fluent::Engine).worker_id { -1 }
end

test 'without <worker> directive' do
conf = config_element()
conf.set_target_worker_ids([])
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end

test 'with <worker 0>' do
conf = config_element()
conf.set_target_worker_ids([0])
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end
data(
'without <worker> directive',
{
target_worker_ids: [],
expected: 1
},
keep: true
)
data(
'with <worker 0>',
{
target_worker_ids: [0],
expected: 1
},
keep: true
)

test 'system_config.workers value after configure' do
assert_system_config_workers_value(data)
end

sub_test_case 'supervisor_mode is false' do
setup do
stub(Fluent::Engine).supervisor_mode { false }
stub(Fluent::Engine).worker_id { 0 }
end

test 'without <worker> directive' do
conf = config_element()
conf.set_target_worker_ids([])
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end

test 'with <worker 0>' do
conf = config_element()
conf.set_target_worker_ids([0])
@p.configure(conf)
assert{ @p.system_config.workers == 1 }
end
test 'system_config.workers value after configure with supervisor_mode' do
stub_supervisor_mode
assert_system_config_workers_value(data)
end
end
end
Expand Down

0 comments on commit d691d6f

Please sign in to comment.