Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minitest warnings #745

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions test/controllers/api/tasks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Api::TasksControllerTest < ActionController::TestCase
get :index
assert_response :success
data = JSON.parse(response.body)
_(data['results'].count).must_equal 5
assert_equal 5, data['results'].count
end

it 'supports searching' do
get :index, params: { :search => 'label = Actions::User::Create' }
assert_response :success
data = JSON.parse(response.body)
_(data['results'].count).must_equal 5
assert_equal 5, data['results'].count
end

it 'renders task ids when searching by resource id' do
Expand All @@ -33,15 +33,15 @@ class Api::TasksControllerTest < ActionController::TestCase
get :index, params: { :search => "label = Actions::Katello::Product::Create and resource_id = 1" }
assert_response :success
data = JSON.parse(response.body)
_(data['results'].first["id"]).must_equal task.id
assert_equal task.id, data['results'].first["id"]
end

it 'supports ordering by duration' do
get :index, params: { :sort_by => 'duration' }
assert_response :success
data = JSON.parse(response.body)
_(data.dig('sort', 'by')).must_equal 'duration'
_(data['results'].count).must_equal 5
assert_equal 'duration', data.dig('sort', 'by')
assert_equal 5, data['results'].count
end

context 'with current taxonomies' do
Expand All @@ -53,9 +53,9 @@ class Api::TasksControllerTest < ActionController::TestCase
get :index, params: { organization_id: org1.id }
assert_response :success
results = JSON.parse(response.body)['results']
_(results.count).must_equal 6
_(results.map { |r| r['id'] }).must_include org1_task.id
_(results.map { |r| r['id'] }).wont_include org2_task.id
assert_equal 6, results.count
assert_includes results.map { |r| r['id'] }, org1_task.id
assert_not_includes results.map { |r| r['id'] }, org2_task.id
end
end
end
Expand All @@ -66,7 +66,7 @@ class Api::TasksControllerTest < ActionController::TestCase
post :bulk_search, params: { :searches => [{ :type => "task", :task_id => task.id, :search_id => "1" }] }
assert_response :success
data = JSON.parse(response.body)
_(data[0]['results'][0]['id']).must_equal task.id
assert_equal task.id, data[0]['results'][0]['id']
end

it 'can search for a specific resource' do
Expand All @@ -77,7 +77,7 @@ class Api::TasksControllerTest < ActionController::TestCase

assert_response :success
data = JSON.parse(response.body)
_(data[0]['results'][0]['id']).must_equal task.id
assert_equal task.id, data[0]['results'][0]['id']
end
end

Expand Down Expand Up @@ -108,7 +108,7 @@ class Api::TasksControllerTest < ActionController::TestCase
get :show, params: { id: task.id }, session: set_session_user
assert_response :success
data = JSON.parse(response.body)
_(data['duration']).must_equal task.duration.in_seconds.to_s
assert_equal task.duration.in_seconds.to_s, data['duration']
end
end

Expand All @@ -118,7 +118,7 @@ class Api::TasksControllerTest < ActionController::TestCase
get :index, session: set_session_user
assert_response :success
data = JSON.parse(response.body)
_(data['results'][0]['duration']).must_equal task.duration.in_seconds.to_s
assert_equal task.duration.in_seconds.to_s, data['results'][0]['duration']
end
end

Expand Down Expand Up @@ -189,17 +189,17 @@ def self.while_suspended
wait_for { ForemanTasks::Task.find_by(external_id: triggered.id).state == 'running' }

task = ForemanTasks::Task.where(:external_id => triggered.id).first
_(task.state).must_equal 'running'
_(task.result).must_equal 'pending'
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
_(task.state).must_equal 'stopped'
_(task.result).must_equal 'success'
_(task.main_action.output['proxy_output']).must_equal('result' => 'success')
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
12 changes: 6 additions & 6 deletions test/controllers/tasks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,30 @@ def in_taxonomy_scope(organization, location = nil)
@controller.stubs(:params).returns(:search => "id = #{task.id}")
in_taxonomy_scope(organizations.first) do |_o, _l|
results = @controller.send(:filter, ForemanTasks::Task)
_(results.map(&:id).sort).must_equal [task.id]
assert_equal [task.id], results.map(&:id).sort
end
end

it 'does not scope by taxonomy if unset' do
organizations
tasks
_(@controller.send(:current_taxonomy_search)).must_equal ''
assert_equal '', @controller.send(:current_taxonomy_search)
results = @controller.send(:filter, ForemanTasks::Task)
_(results.map(&:id).sort).must_equal tasks.map(&:id).sort
assert_equal tasks.map(&:id).sort, results.map(&:id).sort
end

it 'scopes by organization if set' do
scoped, _, unscoped = tasks
in_taxonomy_scope(organizations.first) do |o, _l|
_(@controller.send(:current_taxonomy_search)).must_equal "(organization_id = #{o.id})"
assert_equal "(organization_id = #{o.id})", @controller.send(:current_taxonomy_search)
results = @controller.send(:filter, ForemanTasks::Task)
_(results.map(&:id).sort).must_equal [scoped, unscoped].map(&:id).sort
assert_equal [scoped, unscoped].map(&:id).sort, results.map(&:id).sort
end
end

it 'scopes by org and location if set' do
in_taxonomy_scope(organizations.first, FactoryBot.create(:location)) do |o, l|
_(@controller.send(:current_taxonomy_search)).must_equal "(organization_id = #{o.id} AND location_id = #{l.id})"
assert_equal "(organization_id = #{o.id} AND location_id = #{l.id})", @controller.send(:current_taxonomy_search)
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions test/helpers/foreman_tasks/foreman_tasks_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ class ForemanTasksHelperTest < ActionView::TestCase
it 'prepares items for index correctly' do
stubs(:action_name).returns('index')
items = breadcrumb_items
_(items.count).must_equal 1
_(items.first[:caption]).must_equal 'Tasks'
_(items.first[:url]).must_be_nil
assert_equal 1, items.count
assert_equal 'Tasks', items.first[:caption]
assert_nil items.first[:url]
end

it 'prepares items for show correctly' do
@task = FactoryBot.build(:dynflow_task, :user_create_task)
@task.action = 'A task'
stubs(:action_name).returns('show')
items = breadcrumb_items
_(items.map { |i| i[:caption] }).must_equal ['Tasks', 'A task']
_(items.last[:url]).must_be_nil
assert_equal(['Tasks', 'A task'], items.map { |i| i[:caption] })
assert_nil items.last[:url]
end

it 'prepares items for sub tasks correctly' do
Expand All @@ -31,8 +31,8 @@ class ForemanTasksHelperTest < ActionView::TestCase
@task.action = 'A task'
stubs(:action_name).returns('sub_tasks')
items = breadcrumb_items
_(items.map { |i| i[:caption] }).must_equal ['Tasks', 'A task', 'Sub tasks']
_(items.last[:url]).must_be_nil
assert_equal(['Tasks', 'A task', 'Sub tasks'], items.map { |i| i[:caption] })
assert_nil items.last[:url]
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/foreman_tasks/tasks_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class TasksHelperTest < ActionView::TestCase
end

it 'formats the task input properly' do
_(format_task_input(@task)).must_equal("Create user 'Anonymous Admin'")
assert_equal "Create user 'Anonymous Admin'", format_task_input(@task)
end

it 'displays the dash if task is nil' do
_(format_task_input(nil)).must_equal('-')
assert_equal '-', format_task_input(nil)
end
end

Expand All @@ -37,7 +37,7 @@ class TasksHelperTest < ActionView::TestCase

it 'formats the task input properly' do
response = "product 'product-2'; organization 'test-0'"
_(format_task_input(@task)).must_equal("Create #{response}")
assert_equal("Create #{response}", format_task_input(@task))
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/lib/actions/middleware/keep_current_request_id_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ def finalize
it 'stores the id on planning' do
::Logging.mdc['request'] = expected_id
action = create_and_plan_action(DummyAction)
_(action.input[:current_request_id]).must_equal expected_id
assert_equal expected_id, action.input[:current_request_id]
end

it 'restores the id for run' do
::Logging.mdc['request'] = expected_id
action = create_and_plan_action(DummyAction, true)
action = run_action action
_(action.output[:run_result]).must_equal expected_id
assert_equal expected_id, action.output[:run_result]
end

it 'restores the id for finalize' do
::Logging.mdc['request'] = expected_id
action = create_and_plan_action(DummyAction, true)
action = finalize_action(run_action(action))
_(action.output[:finalize_result]).must_equal expected_id
assert_equal expected_id, action.output[:finalize_result]
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions test/lib/concerns/polling_action_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ class Action < ::Dynflow::Action
let(:default_intervals) { [0.5, 1, 2, 4, 8, 16] }

it 'is extends the polling action module' do
_(::Dynflow::Action::Polling.ancestors.first).must_equal ForemanTasks::Concerns::PollingActionExtensions
assert_equal ForemanTasks::Concerns::PollingActionExtensions, ::Dynflow::Action::Polling.ancestors.first
end

it 'does not modify polling intervals by default' do
_(Action.allocate.poll_intervals).must_equal default_intervals
assert_equal default_intervals, Action.allocate.poll_intervals
end

it 'cannot make intervals shorter than 0.5 seconds' do
Setting.expects(:[]).with(:foreman_tasks_polling_multiplier).returns 0
_(Action.allocate.poll_intervals).must_equal(default_intervals.map { 0.5 })
assert_equal default_intervals.map { 0.5 }, Action.allocate.poll_intervals
end

it 'can be used to make the intervals longer' do
value = 5
Setting.expects(:[]).with(:foreman_tasks_polling_multiplier).returns value
_(Action.allocate.poll_intervals).must_equal(default_intervals.map { |i| i * value })
assert_equal default_intervals.map { |i| i * value }, Action.allocate.poll_intervals
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/tasks/generate_task_actions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GenerateTaskActionsTest < ActiveSupport::TestCase
end

assert_match(%r{Generating action for #{tasks.count} tasks}, stdout)
_(ForemanTasks::Task.where(:action => label).count).must_equal tasks.count
assert_equal tasks.count, ForemanTasks::Task.where(:action => label).count
assert_match(%r{Processed #{tasks.count}/#{tasks.count} tasks}, stdout)
end

Expand Down
8 changes: 4 additions & 4 deletions test/unit/actions/action_with_sub_plans_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def run; end
end

specify 'the sub-plan stores the information about its parent' do
_(task.sub_tasks.size).must_equal 1
_(task.sub_tasks.first.label).must_equal ChildAction.name
assert_equal 1, task.sub_tasks.size
assert_equal ChildAction.name, task.sub_tasks.first.label
end

specify "the locks of the sub-plan don't colide with the locks of its parent" do
child_task = task.sub_tasks.first
assert_not(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")
assert found, "the action is linked properly"
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions test/unit/actions/bulk_action_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ def plan(_target, options = {})
Target.expects(:unscoped).returns(Target)
Target.expects(:where).with(:id => targets.map(&:id)).returns(targets)

_(task.sub_tasks.count).must_equal targets.count
assert_equal targets.count, task.sub_tasks.count
success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' }
_(failed).must_be :empty?
_(success.count).must_equal 5
assert_empty failed
assert_equal 5, success.count
end

specify 'it plans a task for each target even if target cannot be found' do
Target.expects(:unscoped).returns(Target)
Target.expects(:where).with(:id => targets.map(&:id)).returns(targets.take(4))

_(task.sub_tasks.count).must_equal targets.count
assert_equal targets.count, task.sub_tasks.count
success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' }
_(success.count).must_equal 4
_(failed.count).must_equal 1
assert_equal 4, success.count
assert_equal 1, failed.count
end

specify "it handles keyword arguments as indifferent hashes when they're being flattened" do
Expand All @@ -61,8 +61,8 @@ def plan(_target, options = {})
task = ForemanTasks::Task.where(:external_id => triggered.id).first
wait_for { task.reload.state == 'stopped' }
task = task.sub_tasks.first
_(task.input[:kw_string]).must_equal 7
_(task.input[:kw_symbol]).must_equal 7
assert_equal 7, task.input[:kw_string]
assert_equal 7, task.input[:kw_symbol]
end

specify 'it allows setting concurrency limit' do
Expand All @@ -71,7 +71,7 @@ def plan(_target, options = {})

triggered = ForemanTasks.trigger(ParentAction, ChildAction, targets, concurrency_limit: 25)
task = ForemanTasks::Task.where(:external_id => triggered.id).first
_(task.execution_plan.entry_action.concurrency_limit).must_equal 25
assert_equal 25, task.execution_plan.entry_action.concurrency_limit
end
end
end
Expand Down
Loading