Skip to content

Commit

Permalink
Fixes #25736 - Middleware test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Dec 19, 2018
1 parent e1525f6 commit a17240b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/unit/actions/middleware/keep_current_request_id_test.rb
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

0 comments on commit a17240b

Please sign in to comment.