Sha256: 2df52543d93e313cca72451d1c377b5c23469424a1930ef76a037c6efb9a33c4

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 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)
        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
        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))
        assert_equal expected_id, action.output[:finalize_result]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-10.0.1 test/lib/actions/middleware/keep_current_request_id_test.rb
foreman-tasks-10.0.0 test/lib/actions/middleware/keep_current_request_id_test.rb