1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
# frozen_string_literal: true
module Aws
module Stubbing
module Protocols
class EC2
def stub_data(api, operation, data)
resp = Seahorse::Client::Http::Response.new
resp.status_code = 200
resp.body = build_body(api, operation, data) if operation.output
resp.headers['Content-Length'] = resp.body.size
resp.headers['Content-Type'] = 'text/xml;charset=UTF-8'
resp.headers['Server'] = 'AmazonEC2'
resp
end
def stub_error(error_code)
http_resp = Seahorse::Client::Http::Response.new
http_resp.status_code = 400
http_resp.body = <<-XML.strip
<ErrorResponse>
<Error>
<Code>#{error_code}</Code>
<Message>stubbed-response-error-message</Message>
</Error>
</ErrorResponse>
XML
http_resp
end
private
def build_body(api, operation, data)
xml = []
Xml::Builder.new(operation.output, target:xml).to_xml(data)
xml.shift
xml.pop
xmlns = "http://ec2.amazonaws.com/doc/#{api.version}/".inspect
xml.unshift(" <requestId>stubbed-request-id</requestId>")
xml.unshift("<#{operation.name}Response xmlns=#{xmlns}>\n")
xml.push("</#{operation.name}Response>\n")
xml.join
end
end
end
end
end
|