module Aws::ClientStubs
def api_requests(options = {})
-
(NotImplementedError)
- Raises `NotImplementedError` when the client
Returns:
-
(Array)
- Returns an array of the api requests made. Each request
Options Hash:
(**options)
-
:exclude_presign
(Boolean
) -- Set to true to filter
Parameters:
-
options
(Hash
) -- The options for the api requests.
def api_requests(options = {}) if @config.stub_responses @config.api_requests_mutex.synchronize do if options[:exclude_presign] @config.api_requests.reject {|req| req[:context][:presigned_url] } else @config.api_requests end end else msg = 'This method is only implemented for stubbed clients, and is '\ 'available when you enable stubbing in the constructor with `stub_responses: true`' raise NotImplementedError.new(msg) end end
def apply_stubs(operation_name, stubs)
def apply_stubs(operation_name, stubs) @config.stubs_mutex.synchronize do @config.stubs[operation_name.to_sym] = stubs end end
def convert_stub(operation_name, stub, context)
plugin to provide a HTTP response that triggers all normal events
HTTP response (when possible). This enables the response stubbing
This method converts the given stub data and converts it to a
def convert_stub(operation_name, stub, context) case stub when Proc then convert_stub(operation_name, stub.call(context), context) when Exception, Class then { error: stub } when String then service_error_stub(stub) else http_response_stub(operation_name, stub) end end
def data_to_http_resp(operation_name, data)
def data_to_http_resp(operation_name, data) api = @config.api operation = api.operation(operation_name) ParamValidator.new(operation.output, input: false).validate!(data) protocol_helper.stub_data(api, operation, data) end
def hash_to_http_resp(data)
def hash_to_http_resp(data) http_resp = Seahorse::Client::Http::Response.new http_resp.status_code = data[:status_code] http_resp.headers.update(data[:headers]) http_resp.body = data[:body] http_resp end
def http_response_stub(operation_name, data)
def http_response_stub(operation_name, data) if Hash === data && data.keys.sort == [:body, :headers, :status_code] { http: hash_to_http_resp(data) } else { http: data_to_http_resp(operation_name, data) } end end
def next_stub(context)
- Api: - private
def next_stub(context) operation_name = context.operation_name.to_sym stub = @config.stubs_mutex.synchronize do stubs = @config.stubs[operation_name] || [] case stubs.length when 0 then stub_data(operation_name) when 1 then stubs.first else stubs.shift end end stub = convert_stub(operation_name, stub, context) stub[:mutex] = Mutex.new stub end
def protocol_helper
def protocol_helper case @config.api.metadata['protocol'] when 'json' then Stubbing::Protocols::Json when 'rest-json' then Stubbing::Protocols::RestJson when 'rest-xml' then Stubbing::Protocols::RestXml when 'query' then Stubbing::Protocols::Query when 'ec2' then Stubbing::Protocols::EC2 when 'smithy-rpc-v2-cbor' then Stubbing::Protocols::RpcV2 when 'api-gateway' then Stubbing::Protocols::ApiGateway else raise 'unsupported protocol' end.new end
def service_error_stub(error_code)
def service_error_stub(error_code) { http: protocol_helper.stub_error(error_code) } end
def setup_stubbing
- Api: - private
def setup_stubbing if Hash === @config.stub_responses @config.stub_responses.each do |operation_name, stubs| apply_stubs(operation_name, Array === stubs ? stubs : [stubs]) end end end
def stub_data(operation_name, data = {})
-
(Structure)
- Returns a stubbed response data structure. The
Parameters:
-
data
(Hash
) -- -
operation_name
(Symbol
) --
def stub_data(operation_name, data = {}) Stubbing::StubData.new(@config.api.operation(operation_name)).stub(data) end
def stub_responses(operation_name, *stubs)
-
(RuntimeError)
- Raises a runtime error when called
Returns:
-
(void)
-
Parameters:
-
stubs
(Mixed
) -- One or more responses to return from the named -
operation_name
(Symbol
) --
def stub_responses(operation_name, *stubs) if @config.stub_responses apply_stubs(operation_name, stubs.flatten) else msg = 'stubbing is not enabled; enable stubbing in the constructor '\ 'with `:stub_responses => true`' raise msg end end