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 7b3315d
Showing 1 changed file with 67 additions and 108 deletions.
175 changes: 67 additions & 108 deletions test/plugin/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,125 +154,84 @@ 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 when_supervisor_mode_is_true(data)
stub(Fluent::Engine).supervisor_mode { true }
stub(Fluent::Engine).worker_id { -1 }
assert_system_config_workers_value(data)
end

def when_supervisor_mode_is_false(data)
stub(Fluent::Engine).supervisor_mode { false }
stub(Fluent::Engine).worker_id { 0 }
assert_system_config_workers_value(data)
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
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
data(
'without <worker> directive',
{
target_worker_ids: [],
expected: 3
}
)
data(
'with <worker 0>',
{
target_worker_ids: [0],
expected: 1
}
)
data(
'with <worker 0-1>',
{
target_worker_ids: [0, 1],
expected: 2
}
)
data(
'with <worker 0-2>',
{
target_worker_ids: [0, 1, 2],
expected: 3
}
)
test 'system_config.workers value after configure' do
when_supervisor_mode_is_true(data)
when_supervisor_mode_is_false(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
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
data(
'without <worker> directive',
{
target_worker_ids: [],
expected: 1
}
)
data(
'with <worker 0>',
{
target_worker_ids: [0],
expected: 1
}
)
test 'system_config.workers value after configure' do
when_supervisor_mode_is_true(data)
when_supervisor_mode_is_false(data)
end
end
end
Expand Down

0 comments on commit 7b3315d

Please sign in to comment.