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

stub_responses with Hash vs. Type #1097

Closed
durandom opened this issue Feb 18, 2016 · 3 comments
Closed

stub_responses with Hash vs. Type #1097

durandom opened this issue Feb 18, 2016 · 3 comments

Comments

@durandom
Copy link

Hi,
first of all I have to give you props for the awesome client_stubbing feature. A great way to reliably write test against API mocks.

To my understanding the stub_responses method should not care if passed a Hash or a typed result, eg. Hash vs Aws::SQS::Types::GetQueueAttributesResult

I prepared a little script to illustrate this. Is this intended?
If you point me to the code where something goes wrong, I'm happy to prepare a PR

#!/bin/env ruby
require 'aws-sdk'

queue_url = "https://sqs.eu-central-1.amazonaws.com/123456789/queue-name"
client    = Aws::SQS::Client.new(:stub_responses => true)

# use stub_data as SQS::Type
p stub_data = client.stub_data(:get_queue_attributes, :attributes => {'QueueArn' => 'arn'})
#<struct Aws::SQS::Types::GetQueueAttributesResult attributes={"QueueArn"=>"arn"}>


client.stub_responses(:get_queue_attributes, stub_data)
p client.get_queue_attributes(:queue_url => queue_url, attribute_names: ['QueueArn'])
#<struct Aws::SQS::Types::GetQueueAttributesResult attributes={"QueueArn"=>"arn"}>

# all good here, we get QueueArn => "arn"

# use stub_data as Hash
p stub_data = stub_data.to_h
#{:attributes=>{"QueueArn"=>"arn"}}

client.stub_responses(:get_queue_attributes, stub_data)
p client.get_queue_attributes(:queue_url => queue_url, attribute_names: ['QueueArn'])
#<struct Aws::SQS::Types::GetQueueAttributesResult attributes={""=>""}>

# oops, attributes is there, but its empty?!
@trevorrowe
Copy link
Member

Thank you for reporting the issue and for the excellent reproduction steps. Off the top of my head I'm not sure what the root cause it, but I'll take a look.

@trevorrowe
Copy link
Member

I found the issue and the fix was pretty straight forward. When stubbing response data with a hash, the data is used to generate an HTTP response. There was a bug in how we created the response body for Query based services that used flattened XML maps. The fix should go out with our next release.

@durandom
Copy link
Author

❤️ for fixing this so fast

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

2 participants