Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Fix for response stubbing and streaming responses.
Browse files Browse the repository at this point in the history
Fixes #197.
  • Loading branch information
trevorrowe committed Jan 24, 2015
1 parent 50d8a23 commit 3e2ee8f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Unreleased Changes
------------------

* Issue - Response Stubbing - Resolved an issue where the response stubbing
plugin would not correctly populate the response target for streaming API calls,
such as `Aws::S3::Client#get_object`. Fixes GitHub issue #197.

* Issue - Aws::EC2 - Added missing paginator configuration for
`Aws::EC2::Client#describe_instances`. Fixes GitHub issue #196.

Expand Down
18 changes: 18 additions & 0 deletions aws-sdk-core/lib/aws-sdk-core/plugins/stub_responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,27 @@ def apply_stub(resp, stub)
resp.error = stub.new
else
resp.data = stub
stub_http_body(resp) if streaming?(resp)
end
end

def streaming?(resp)
if output = resp.context.operation.output
payload = output.payload_member
payload && payload.definition['streaming'] == true
else
false
end
end

def stub_http_body(resp)
payload = resp.context.operation.output.payload
body = resp.context.http_response.body
body.write(resp.data[payload])
body.rewind if body.respond_to?(:rewind)
resp.data[payload] = body
end

end
end
end
Expand Down
14 changes: 14 additions & 0 deletions aws-sdk-core/spec/aws/stubbing/stub_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'stringio'

module Aws
module ClientStubs
Expand Down Expand Up @@ -177,6 +178,19 @@ module ClientStubs
end

end

describe 'streaming resposnes' do

it 'stubs the HTTP response target when with streaming APIs' do
s3 = S3::Client.new(stub_responses: true)
s3.stub_responses(:get_object, { body: 'data' })
io = StringIO.new
resp = s3.get_object(bucket:'bucket', key:'key', response_target: io)
expect(resp.body.read).to eq('data')
expect(resp.body).to be(io)
expect(resp.context.http_response.body).to be(io)
end
end
end
end
end
Expand Down

0 comments on commit 3e2ee8f

Please sign in to comment.