-
Notifications
You must be signed in to change notification settings - Fork 57
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
Do not send response to CloudFormation when testing with sam local #54
Comments
You can do this by mocking the The normal implementation builds a response body. This behavior you want to keep so you can test the response.
So if you replace custom-resource-helper/crhelper/resource_helper.py Lines 225 to 242 in 3c7e40e
I'd love to see a built-in way of supporting such testing without so much monkey patching :-) |
@iainelder please forgive my ignorance, but are you able to explain why this doesn't work? @patch('crhelper.utils._send_response')
@patch('crhelper.resource_helper.CfnResource._set_timeout', Mock())
def test_create(self, mock_send):
event = {
"RequestType": "Create",
"RequestId": "test-event-id",
"StackId": "arn/test-stack-id/guid",
"LogicalResourceId": "TestResourceId",
"ResponseURL": "response_url",
"ResourceProperties": {
"MyData": "SomeProperty"
}
}
lambda_function.handler(event, "")
# Do some asserting on mock_send.call_args_list |
@verbitan , it's not a complete example and you haven't shown me what you expect or what you get instead. So it's hard to say why it doesn't work. It's been a while since I've used crhelper, but I did develop a working solution for this on a previous project. I've extracted from it a minimal example and I've published it to a new GitHub repo: https://github.com/iainelder/custom-resource-helper-mock You should be able to set up the environment and run the example in PyTest. The Does that help? Can you adapt it for your use case? |
That's perfect @iainelder, thank you! |
When testing my custom resource with sam local, the resource helper tries to send a response to CloudFormation.
It generates an error since I am using fake information in my request payload.
Example:
It would be nice to disable response sending to cfn when testing with sam local.
crhelper version: 2.0.10
The text was updated successfully, but these errors were encountered: