Sha256: 54f676664c0cf691b7f2d1c192e632eee70a65f16183bcafe7be447f70dc7235

Contents?: true

Size: 1.36 KB

Versions: 52

Compression:

Stored size: 1.36 KB

Contents

require 'securerandom'

module Support
  class DummyProxyAction < Actions::ProxyAction
    class DummyProxyVersion
      attr_reader :version

      def initialize(version)
        @version = { 'version' => version }
      end
    end

    class DummyProxy
      attr_reader :log, :task_triggered, :uuid

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

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

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

      def url
        'proxy.example.com'
      end

      def statuses
        { version: DummyProxyVersion.new('1.21.0') }
      end
    end

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

    def proxy_operation_name
      'support'
    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

52 entries across 52 versions & 1 rubygems

Version Path
foreman-tasks-0.16.1 test/support/dummy_proxy_action.rb
foreman-tasks-0.17.0 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.9 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.8 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.7 test/support/dummy_proxy_action.rb
foreman-tasks-0.16.0 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.6 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.5 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.4 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.3 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.2 test/support/dummy_proxy_action.rb
foreman-tasks-0.15.1 test/support/dummy_proxy_action.rb