-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Programmable stubs #1120
Comments
Thanks for the feature request. Depending on what testing framework you use, there are methods to achieve this. For example, using RSpec, you can do the following: client = Aws::S3::Client.new(stub_responses: true)
# success
allow(client).to receive(:delete_bucket).with(bucket:'aws-sdk').and_return(client.stub_data(:delete_bucket))
# error
allow(client).to receive(:delete_bucket).with(bucket:'aws-sdk-not-empty').and_raise(Aws::S3::Errors::BucketNotEmptyError)
# all other requests will hit the default stubs Moving this sort of functionality into the client stubbing interface could be helpful as well. The above example can be a bit verbose, and depends on using a mocking/stubbing library. Just sharing it in case it can help. |
Thanks for the tip. A downside to that approach is you lose validation on the names of methods you've stubbed (with There are probably ways to use rspec/etc to help prevent that but takes care. |
I agree. It also prevents the SDK from executing the request stack. Response stubbing very carefully only by-passes the network request. This ensures any handlers or plugins still trigger. The rspec |
Moved to the feature request backlog. |
I think this is already possible by passing a To take your original example, you should be able to do something like this: client.stub_responses(:delete_certificate, -> (context) {
context.params[:certificate_arn] == "foo" ? "YourError" : {...}
}) |
It would be great if I could use a callback to determine how to respond to a stubbed request. For example, I want to return an error if a server certificate named
foo
is deleted but return a successful response for anything else.The text was updated successfully, but these errors were encountered: