Sha256: 453a7277723f3aec97daf8e73b15c49f1fa1ff6f8f2ea49d773b518ebb28a086

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

require 'securerandom'

module Support
  class DummyProxyAction < Actions::ProxyAction
    class DummyProxy
      attr_reader :log, :task_triggered, :uuid

      def initialize
        @log = Hash.new { |h, k| h[k] = [] }
        @task_triggered = Concurrent.future
        @uuid = SecureRandom.uuid
      end

      def trigger_task(*args)
        @log[:trigger_task] << args
        @task_triggered.success(true)
        { 'task_id' => @uuid }
      end

      def cancel_task(*args)
        @log[:cancel_task] << args
      end

      def url
        'proxy.example.com'
      end
    end

    class ProxySelector < ::ForemanTasks::ProxySelector
      def available_proxies
        { :global => [DummyProxyAction.proxy] }
      end
    end

    def proxy
      self.class.proxy
    end

    def task
      super
    rescue ActiveRecord::RecordNotFound
      ForemanTasks::Task::DynflowTask.new.tap { |task| task.id = proxy.uuid }
    end

    class << self
      attr_reader :proxy
    end

    def self.reset
      @proxy = DummyProxy.new
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
foreman-tasks-0.14.4 test/support/dummy_proxy_action.rb
foreman-tasks-0.14.3 test/support/dummy_proxy_action.rb
foreman-tasks-0.14.2 test/support/dummy_proxy_action.rb
foreman-tasks-0.14.1 test/support/dummy_proxy_action.rb
foreman-tasks-0.14.0 test/support/dummy_proxy_action.rb
foreman-tasks-0.13.4 test/support/dummy_proxy_action.rb
foreman-tasks-0.13.3 test/support/dummy_proxy_action.rb
foreman-tasks-0.13.2 test/support/dummy_proxy_action.rb
foreman-tasks-0.13.1 test/support/dummy_proxy_action.rb
foreman-tasks-0.13.0 test/support/dummy_proxy_action.rb
foreman-tasks-0.12.2 test/support/dummy_proxy_action.rb
foreman-tasks-0.12.1 test/support/dummy_proxy_action.rb
foreman-tasks-0.12.0 test/support/dummy_proxy_action.rb