Skip to content

Commit

Permalink
DRY'd up query and rest-xml error stubbing.
Browse files Browse the repository at this point in the history
See #873
  • Loading branch information
trevorrowe committed Jul 21, 2015
1 parent c6c2deb commit d626b58
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased Changes
------------------

* Issue - Stubbing - Added missing support for stubbing query protocol errors by their
error code.

2.1.7 (2015-07-14)
------------------

Expand Down
3 changes: 2 additions & 1 deletion aws-sdk-core/lib/aws-sdk-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ module Signers
# @api private
module Stubbing
autoload :EmptyStub, 'aws-sdk-core/stubbing/empty_stub'
autoload :StubData, 'aws-sdk-core/stubbing/stub_data'
autoload :DataApplicator, 'aws-sdk-core/stubbing/data_applicator'
autoload :StubData, 'aws-sdk-core/stubbing/stub_data'
autoload :XmlError, 'aws-sdk-core/stubbing/xml_error'
module Protocols
autoload :EC2, 'aws-sdk-core/stubbing/protocols/ec2'
autoload :Json, 'aws-sdk-core/stubbing/protocols/json'
Expand Down
9 changes: 1 addition & 8 deletions aws-sdk-core/lib/aws-sdk-core/stubbing/protocols/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ def stub_data(api, operation, data)
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.body = XmlError.new(error_code).to_xml
http_resp
end

Expand Down
9 changes: 1 addition & 8 deletions aws-sdk-core/lib/aws-sdk-core/stubbing/protocols/rest_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@ def body_for(api, operation, rules, data)
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.body = XmlError.new(error_code).to_xml
http_resp
end

Expand Down
22 changes: 22 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core/stubbing/xml_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Aws
module Stubbing
class XmlError

def initialize(error_code)
@error_code = error_code
end

def to_xml
<<-XML.strip
<ErrorResponse>
<Error>
<Code>#{@error_code}</Code>
<Message>stubbed-response-error-message</Message>
</Error>
</ErrorResponse>
XML
end

end
end
end
12 changes: 12 additions & 0 deletions aws-sdk-core/spec/aws/stubbing/protocols/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ def normalize(xml)
XML
end

it 'can stub errors' do
resp = Query.new.stub_error('error-code')
expect(normalize(resp.body.string)).to eq(normalize(<<-XML))
<ErrorResponse>
<Error>
<Code>error-code</Code>
<Message>stubbed-response-error-message</Message>
</Error>
</ErrorResponse>
XML
end

end
end
end
Expand Down
12 changes: 12 additions & 0 deletions aws-sdk-core/spec/aws/stubbing/protocols/rest_xml_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ def normalize(xml)
JSON
end

it 'can stub errors' do
resp = RestXml.new.stub_error('error-code')
expect(normalize(resp.body.string)).to eq(normalize(<<-XML))
<ErrorResponse>
<Error>
<Code>error-code</Code>
<Message>stubbed-response-error-message</Message>
</Error>
</ErrorResponse>
XML
end

end
end
end
Expand Down

0 comments on commit d626b58

Please sign in to comment.