Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response not written to file when using :response_target with stubbed_responses: true #1882

Closed
ghost opened this issue Sep 25, 2018 · 6 comments

Comments

@ghost
Copy link

ghost commented Sep 25, 2018

Issue description

When I use stub_responses: true when creating a client for S3, I expect the behavior
of response_target options to be the same as a client without this option.

Expected behavior

If a response is stubbed, it is still a response and I would assert that code relying on the response body
to be written to a file should work whether the s3 client is stubbed or not.

Current behavior

When the client has stub_responses: true the file is never written to disk.

Gem name

aws-sdk-s3 (1.20.0)

Version of Ruby, OS environment

macOS High Sierra 10.13.6, ruby-2.5.1

Code snippets / steps to reproduce

[andrew.newell@C02N5BBFG3QD aws_sdk_testing ]$ irb   
2.5.1 :001 > require 'aws-sdk-s3'
 => true 
2.5.1 :002 > @s3_client = Aws::S3::Client.new(stub_responses: true)
 => #<Aws::S3::Client> 
2.5.1 :003 > data = @s3_client.stub_data(:get_object, body: 'this is a body')
 => #<struct Aws::S3::Types::GetObjectOutput body="this is a body", delete_marker=false, accept_ranges="AcceptRanges", expiration="Expiration", restore="Restore", last_modified=2018-09-25 13:27:31 -0400, content_length=0, etag="ETag", missing_meta=0, version_id="ObjectVersionId", cache_control="CacheControl", content_disposition="ContentDisposition", content_encoding="ContentEncoding", content_language="ContentLanguage", content_range="ContentRange", content_type="ContentType", expires=2018-09-25 13:27:31 -0400, expires_string="ExpiresString", website_redirect_location="WebsiteRedirectLocation", server_side_encryption="ServerSideEncryption", metadata={}, sse_customer_algorithm="SSECustomerAlgorithm", sse_customer_key_md5="SSECustomerKeyMD5", ssekms_key_id="SSEKMSKeyId", storage_class="StorageClass", request_charged="RequestCharged", replication_status="ReplicationStatus", parts_count=0, tag_count=0> 
2.5.1 :004 > @s3_client.stub_responses(:get_object, data)
 => [{:data=>#<struct Aws::S3::Types::GetObjectOutput body="this is a body", delete_marker=false, accept_ranges="AcceptRanges", expiration="Expiration", restore="Restore", last_modified=2018-09-25 13:27:31 -0400, content_length=0, etag="ETag", missing_meta=0, version_id="ObjectVersionId", cache_control="CacheControl", content_disposition="ContentDisposition", content_encoding="ContentEncoding", content_language="ContentLanguage", content_range="ContentRange", content_type="ContentType", expires=2018-09-25 13:27:31 -0400, expires_string="ExpiresString", website_redirect_location="WebsiteRedirectLocation", server_side_encryption="ServerSideEncryption", metadata={}, sse_customer_algorithm="SSECustomerAlgorithm", sse_customer_key_md5="SSECustomerKeyMD5", ssekms_key_id="SSEKMSKeyId", storage_class="StorageClass", request_charged="RequestCharged", replication_status="ReplicationStatus", parts_count=0, tag_count=0>}] 
2.5.1 :005 > @s3_client.get_object({bucket: 'bucket', key: 'key'}, response_target: '/tmp/aws_sdk_testing/output' )
 => #<struct Aws::S3::Types::GetObjectOutput body="this is a body", delete_marker=false, accept_ranges="AcceptRanges", expiration="Expiration", restore="Restore", last_modified=2018-09-25 13:27:31 -0400, content_length=0, etag="ETag", missing_meta=0, version_id="ObjectVersionId", cache_control="CacheControl", content_disposition="ContentDisposition", content_encoding="ContentEncoding", content_language="ContentLanguage", content_range="ContentRange", content_type="ContentType", expires=2018-09-25 13:27:31 -0400, expires_string="ExpiresString", website_redirect_location="WebsiteRedirectLocation", server_side_encryption="ServerSideEncryption", metadata={}, sse_customer_algorithm="SSECustomerAlgorithm", sse_customer_key_md5="SSECustomerKeyMD5", ssekms_key_id="SSEKMSKeyId", storage_class="StorageClass", request_charged="RequestCharged", replication_status="ReplicationStatus", parts_count=0, tag_count=0> 
2.5.1 :006 > exit
[andrew.newell@C02N5BBFG3QD aws_sdk_testing ]$ pwd       
/tmp/aws_sdk_testing
[andrew.newell@C02N5BBFG3QD aws_sdk_testing ]$ ls -alhF
total 0
drwxr-xr-x   2 andrew.newell  wheel    64B Sep 25 13:29 ./
drwxrwxrwt  11 root           wheel   352B Sep 25 13:26 ../
[andrew.newell@C02N5BBFG3QD aws_sdk_testing ]$ 
@ghost
Copy link
Author

ghost commented Sep 25, 2018

This looks like it could be related to #823 and amazon-archives/aws-sdk-core-ruby#197

@srchase srchase added the feature-request A feature should be added or improved. label Oct 22, 2018
@srchase
Copy link
Contributor

srchase commented Oct 22, 2018

Hello @andrew-newell,

Thanks for reporting this issue.

Both of the issues you point to are for the prior version of the SDK. Stubbing for the current version does not support writing the response_target to a file.

I'm marking this a feature request.

@ghost
Copy link
Author

ghost commented Oct 23, 2018

Stubbing for the current version does not support writing the response_target to a file.

@srchase Can you point me to the documentation for this behavior please?

@srchase
Copy link
Contributor

srchase commented Oct 23, 2018

@andrew-newell

Can you give this a try instead?

@s3_client = Aws::S3::Client.new(stub_responses: true)
@s3_client.stub_responses(:get_object, body: 'this is a body')
@s3_client.get_object(response_target: 'output.txt', bucket: 'myBucket', key: 'myKey')

@srchase srchase removed the feature-request A feature should be added or improved. label Oct 23, 2018
@srchase
Copy link
Contributor

srchase commented Oct 23, 2018

You can check out this blog post by @awood45 for some additional reading on Advanced client stubbing in the AWS SDK for Ruby Version 3.

You'll likely be able to accomplish most things with stub_responses. That allows you to set the data or errors that will get returned on the normal client calls you make elsewhere.

@srchase srchase closed this as completed Oct 23, 2018
@ghost
Copy link
Author

ghost commented Nov 1, 2018

@andrew-newell

Can you give this a try instead?

@s3_client = Aws::S3::Client.new(stub_responses: true)
@s3_client.stub_responses(:get_object, body: 'this is a body')
@s3_client.get_object(response_target: 'output.txt', bucket: 'myBucket', key: 'myKey')

Yep, that works. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant