Skip to content

Commit

Permalink
Make rubocop happy
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Feb 15, 2024
1 parent 354c2d1 commit 176f381
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 318 deletions.
50 changes: 25 additions & 25 deletions test/controllers/api/tasks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Api::TasksControllerTest < ActionController::TestCase
results = JSON.parse(response.body)['results']
assert_equal 6, results.count
assert_includes results.map { |r| r['id'] }, org1_task.id
refute_includes results.map { |r| r['id'] }, org2_task.id
assert_not_includes results.map { |r| r['id'] }, org2_task.id
end
end
end
Expand Down Expand Up @@ -176,30 +176,30 @@ def self.while_suspended

describe 'POST /tasks/callback' do
it 'passes the data to the corresponding action' do
Support::DummyProxyAction.reset
ForemanTasks::RemoteTask.any_instance
.expects(:proxy)
.returns(Support::DummyProxyAction.proxy)

triggered = ForemanTasks.trigger(Support::DummyProxyAction,
Support::DummyProxyAction.proxy,
'Proxy::DummyAction',
'foo' => 'bar')
Support::DummyProxyAction.proxy.task_triggered.wait(5)
wait_for { ForemanTasks::Task.find_by(external_id: triggered.id).state == 'running' }

task = ForemanTasks::Task.where(:external_id => triggered.id).first
assert_equal 'running', task.state
assert_equal 'pending', task.result

callback = Support::DummyProxyAction.proxy.log[:trigger_task].first[1].first[1][:action_input][:callback]
post :callback, params: { 'callback' => callback, 'data' => { 'result' => 'success' } }
triggered.finished.wait(5)

task.reload
assert_equal 'stopped', task.state
assert_equal 'success', task.result
assert_equal({ 'result' => 'success' }, task.main_action.output['proxy_output'])
Support::DummyProxyAction.reset
ForemanTasks::RemoteTask.any_instance
.expects(:proxy)
.returns(Support::DummyProxyAction.proxy)

triggered = ForemanTasks.trigger(Support::DummyProxyAction,
Support::DummyProxyAction.proxy,
'Proxy::DummyAction',
'foo' => 'bar')
Support::DummyProxyAction.proxy.task_triggered.wait(5)
wait_for { ForemanTasks::Task.find_by(external_id: triggered.id).state == 'running' }

task = ForemanTasks::Task.where(:external_id => triggered.id).first
assert_equal 'running', task.state
assert_equal 'pending', task.result

callback = Support::DummyProxyAction.proxy.log[:trigger_task].first[1].first[1][:action_input][:callback]
post :callback, params: { 'callback' => callback, 'data' => { 'result' => 'success' } }
triggered.finished.wait(5)

task.reload
assert_equal 'stopped', task.state
assert_equal 'success', task.result
assert_equal({ 'result' => 'success' }, task.main_action.output['proxy_output'])
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/foreman_tasks/foreman_tasks_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ForemanTasksHelperTest < ActionView::TestCase
@task.action = 'A task'
stubs(:action_name).returns('show')
items = breadcrumb_items
assert_equal ['Tasks', 'A task'], items.map { |i| i[:caption] }
assert_equal(['Tasks', 'A task'], items.map { |i| i[:caption] })
assert_nil items.last[:url]
end

Expand All @@ -31,7 +31,7 @@ class ForemanTasksHelperTest < ActionView::TestCase
@task.action = 'A task'
stubs(:action_name).returns('sub_tasks')
items = breadcrumb_items
assert_equal ['Tasks', 'A task', 'Sub tasks'], items.map { |i| i[:caption] }
assert_equal(['Tasks', 'A task', 'Sub tasks'], items.map { |i| i[:caption] })
assert_nil items.last[:url]
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/actions/action_with_sub_plans_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def run; end

specify "the locks of the sub-plan don't colide with the locks of its parent" do
child_task = task.sub_tasks.first
refute child_task.locks.any?, "the lock is ensured by the parent"
assert_not child_task.locks.any?, "the lock is ensured by the parent"
found = ForemanTasks::Link.for_resource(user).where(:task_id => child_task.id).any?
assert found, "the action is linked properly"
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/actions/proxy_action_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ProxyActionTest < ActiveSupport::TestCase

it 'saves the data comming from the proxy to the output and finishes' do
action = run_action(@action, ::Actions::ProxyAction::CallbackData.new('result' => 'success'))
assert_equal({'result' => 'success'}, action.output[:proxy_output])
assert_equal({ 'result' => 'success' }, action.output[:proxy_output])
end

it 'handles connection errors' do
Expand Down Expand Up @@ -141,7 +141,7 @@ class ProxyActionTest < ActiveSupport::TestCase
action.world.stubs(:persistence).returns(persistence)
action.wipe_secrets!(nil)

refute action.input.key?(:secrets)
assert_not action.input.key?(:secrets)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/unit/cleaner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class TasksTest < ActiveSupport::TestCase
assert_equal tasks_to_keep.map(&:id).sort, ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id)

assert_equal 0, ForemanTasks.dynflow.world.persistence
.find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size
.find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size

assert_equal tasks_to_keep.size, ForemanTasks.dynflow.world.persistence
.find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size
.find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size
end

describe "#orphaned_dynflow_tasks" do
Expand Down Expand Up @@ -71,7 +71,7 @@ class TasksTest < ActiveSupport::TestCase
assert_equal tasks_to_keep, ForemanTasks::Task.where(id: tasks_to_keep)

assert_nil ForemanTasks::Link.find_by(id: link_to_delete.id)
refute_nil ForemanTasks::Link.find_by(id: link_to_keep.id)
assert_not_nil ForemanTasks::Link.find_by(id: link_to_keep.id)
end

it 'supports passing empty filter (just delete all)' do
Expand Down
22 changes: 11 additions & 11 deletions test/unit/recurring_logic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ class RecurringLogicsTest < ActiveSupport::TestCase
expected_result_daily = { :minutes => minutes, :hours => hours }
expected_result_weekly = { :minutes => minutes, :hours => hours, :days_of_week => '1,4,6' }
expected_result_monthly = { :minutes => minutes, :hours => hours, :days => days }
assert_equal expected_result_hourly, ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days, days_of_week)
assert_equal expected_result_daily, ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days, days_of_week)
assert_equal expected_result_weekly, ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days, days_of_week)
assert_equal expected_result_hourly, ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days, days_of_week)
assert_equal expected_result_daily, ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days, days_of_week)
assert_equal expected_result_weekly, ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days, days_of_week)
assert_equal expected_result_monthly, ForemanTasks::RecurringLogic.cronline_hash(:monthly, time_hash, days, days_of_week)
end

it 'validates cronline correctly' do
recurring_logic = ::ForemanTasks::RecurringLogic.new_from_cronline('* * * * abc')
refute recurring_logic.valid_cronline?
assert_not recurring_logic.valid_cronline?
recurring_logic = ::ForemanTasks::RecurringLogic.new_from_cronline(nil)
refute recurring_logic.valid_cronline?
assert_not recurring_logic.valid_cronline?
recurring_logic = ::ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
assert recurring_logic.valid_cronline?
recurring_logic = ::ForemanTasks::RecurringLogic.new_from_cronline('0 22 * * mon-fri')
Expand All @@ -71,15 +71,15 @@ class RecurringLogicsTest < ActiveSupport::TestCase
assert parser.can_continue?
parser.max_iteration = 5
parser.expects(:iteration).twice.returns(5)
refute parser.can_continue?
assert_not parser.can_continue?
parser.max_iteration = nil
time = Time.utc(2015, 9, 29, 15, 0)
parser.end_time = time
refute parser.can_continue?(time)
assert_not parser.can_continue?(time)
parser.end_time = time + 120
assert parser.can_continue?(time)
parser.max_iteration = 5
refute parser.can_continue?(time)
assert_not parser.can_continue?(time)
end

it 'generates delay options' do
Expand Down Expand Up @@ -185,17 +185,17 @@ class RecurringLogicsTest < ActiveSupport::TestCase

it 'is invalid when end time in past' do
logic.end_time = (Time.zone.now - 120)
refute logic.valid?
assert_not logic.valid?
end

it 'is invalid when iteration limit < 1' do
logic.max_iteration = 0
refute logic.valid?
assert_not logic.valid?
end

it 'is valid when in active state' do
logic.end_time = (Time.zone.now - 120)
refute logic.valid?
assert_not logic.valid?
logic.state = 'active'
assert logic.valid?
end
Expand Down
Loading

0 comments on commit 176f381

Please sign in to comment.