-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1525f6
commit a17240b
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
test/unit/actions/middleware/keep_current_request_id_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'foreman_tasks_test_helper' | ||
|
||
module ForemanTasks | ||
class KeepCurrentRequestIDTest < ActiveSupport::TestCase | ||
class DummyAction < Actions::EntryAction | ||
def plan(plan = false) | ||
plan_self if plan | ||
end | ||
|
||
def run(event = nil) | ||
output[:run_result] = ::Logging.mdc['request'] | ||
end | ||
|
||
def finalize | ||
output[:finalize_result] = ::Logging.mdc['request'] | ||
end | ||
end | ||
|
||
describe Actions::Middleware::KeepCurrentRequestID do | ||
include ::Dynflow::Testing | ||
|
||
before { @old_id = ::Logging.mdc['request'] } | ||
after { ::Logging.mdc['request'] = @old_id } | ||
|
||
let(:expected_id) { 'an_id' } | ||
|
||
it 'stores the id on planning' do | ||
::Logging.mdc['request'] = expected_id | ||
task = ForemanTasks.sync_task(DummyAction, false) | ||
task.input[:current_request_id].must_equal expected_id | ||
end | ||
|
||
it 'restores the id for run' do | ||
::Logging.mdc['request'] = expected_id | ||
task = ForemanTasks.sync_task(DummyAction, true) | ||
task.output[:run_result].must_equal expected_id | ||
end | ||
|
||
it 'restores the id for finalize' do | ||
::Logging.mdc['request'] = expected_id | ||
task = ForemanTasks.sync_task(DummyAction, true) | ||
task.output[:finalize_result].must_equal expected_id | ||
end | ||
end | ||
end | ||
end |