Sha256: 1537c1120cef42a7daf7ff1b9abb50afbb6b5a5ae5ddbc3be1f25bba2b0d3816

Contents?: true

Size: 1.84 KB

Versions: 17

Compression:

Stored size: 1.84 KB

Contents

module Aws
  module Plugins

    # @seahorse.client.option [Boolean] :stub_responses (false)
    #   Causes the client to return stubbed responses. By default
    #   fake responses are generated and returned. You can specify
    #   the response data to return or errors to raise by calling
    #   {ClientStubs#stub_responses}. See {ClientStubs} for more information.
    #
    #   ** Please note ** When response stubbing is enabled, no HTTP
    #   requests are made, and retries are disabled.
    #
    class StubResponses < Seahorse::Client::Plugin

      option(:stub_responses, false)

      option(:region) do |config|
        'stubbed-region' if config.stub_responses
      end

      option(:credentials) do |config|
        if config.stub_responses
          Credentials.new('stubbed-akid', 'stubbed-secret')
        end
      end

      def add_handlers(handlers, config)
        handlers.add(Handler, step: :send) if config.stub_responses
      end

      def after_initialize(client)
        # disable retries when stubbing responses
        if client.config.stub_responses
          client.handlers.remove(RetryErrors::Handler)
        end
      end

      class Handler < Seahorse::Client::Handler

        def call(context)
          response = Seahorse::Client::Response.new(context: context)
          apply_stub(response, context.client.next_stub(context.operation_name))
          response
        end

        private

        def apply_stub(resp, stub)
          if Exception === stub
            resp.error = stub
          elsif Class === stub && stub.ancestors.include?(Errors::ServiceError)
            resp.error = stub.new(resp.context, 'stubbed error')
          elsif Class === stub && stub.ancestors.include?(Exception)
            resp.error = stub.new
          else
            resp.data = stub
          end
        end

      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
aws-sdk-core-2.0.20 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.19 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.18 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.17 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.16 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.15 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.14 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.13 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.12 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.11 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.10 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.9 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.8 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.7 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.6 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.5 lib/aws-sdk-core/plugins/stub_responses.rb
aws-sdk-core-2.0.4 lib/aws-sdk-core/plugins/stub_responses.rb