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-4.1.6 test/support/dummy_proxy_action.rb
foreman-tasks-5.1.1 test/support/dummy_proxy_action.rb
foreman-tasks-5.1.0 test/support/dummy_proxy_action.rb
foreman-tasks-4.1.5 test/support/dummy_proxy_action.rb
foreman-tasks-4.1.4 test/support/dummy_proxy_action.rb
foreman-tasks-4.1.3 test/support/dummy_proxy_action.rb
foreman-tasks-3.0.6 test/support/dummy_proxy_action.rb
foreman-tasks-5.0.0 test/support/dummy_proxy_action.rb
foreman-tasks-4.1.2 test/support/dummy_proxy_action.rb
foreman-tasks-4.1.1 test/support/dummy_proxy_action.rb
foreman-tasks-4.0.1 test/support/dummy_proxy_action.rb
foreman-tasks-4.1.0 test/support/dummy_proxy_action.rb
foreman-tasks-3.0.5 test/support/dummy_proxy_action.rb
foreman-tasks-4.0.0 test/support/dummy_proxy_action.rb
foreman-tasks-3.0.4 test/support/dummy_proxy_action.rb
foreman-tasks-2.0.3 test/support/dummy_proxy_action.rb
foreman-tasks-3.0.3 test/support/dummy_proxy_action.rb
foreman-tasks-3.0.2 test/support/dummy_proxy_action.rb
foreman-tasks-3.0.1 test/support/dummy_proxy_action.rb
foreman-tasks-3.0.0 test/support/dummy_proxy_action.rb