Sha256: 5cb1de0a0d65d02be320aeec456cc71ee25ef98b0238ec438cf5cd431fa49dc7

Contents?: true

Size: 1.43 KB

Versions: 34

Compression:

Stored size: 1.43 KB

Contents

require 'foreman_tasks_test_helper'

module ForemanTasks
  class KeepCurrentRequestIDTest < ActiveSupport::TestCase
    class DummyAction < Actions::EntryAction
      middleware.use ::Actions::Middleware::KeepCurrentRequestID

      def plan(plan = false)
        plan_self if plan
      end

      def run
        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
        action = create_and_plan_action(DummyAction)
        action.input[:current_request_id].must_equal expected_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
      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
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
foreman-tasks-0.15.10 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.16.1 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.17.0 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.9 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.8 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.7 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.16.0 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.6 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.5 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.4 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.3 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.2 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.1 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-0.15.0 test/lib/actions/middleware/keep_current_request_id_test.rb