Sha256: 915aed397d50f39b042dac98cb8da5b06d86c1348991104ea1cc2d19a66d9029

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 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 = defined?(Concurrent::Promises) ? Concurrent::Promises.resolvable_future : Concurrent.future
        @uuid = SecureRandom.uuid
      end

      def trigger_task(*args)
        @log[:trigger_task] << args
        defined?(Concurrent::Promises) ? @task_triggered.fulfill(true) : @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

2 entries across 2 versions & 1 rubygems

Version Path
foreman-tasks-0.14.6 test/support/dummy_proxy_action.rb
foreman-tasks-0.14.5 test/support/dummy_proxy_action.rb