-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Added test cases and fixed issues for RequestValidator apigateway #7917
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Congratulations on your first contribution!
It seems you've forked LocalStack, could you please push your branch directly to the localstack/localstack
repo, so that the integration-tests-against-pro
action could run? (It can run only for branches inside the repo). Because of the nature of API Gateway, it would be safer to run those as we have quite a lot of integrations.
Otherwise, I only have some minor comments about the test structure and a nit about a logic condition. Great use of all the snapshots, this is really great to see! Thanks a lot for tackling this and getting RequestValidator
in parity with AWS! 🎉
if key in ["validateRequestParameters", "validateRequestBody"]: | ||
if value.lower() == "true": | ||
value = True | ||
else: | ||
value = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if key in ["validateRequestParameters", "validateRequestBody"]: | |
if value.lower() == "true": | |
value = True | |
else: | |
value = False | |
elif key in ("validateRequestParameters", "validateRequestBody"): | |
value = value and value.lower() == "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simplify the logic a bit here, and also guard if value
is not in the dictionary. Not sure what would actually happen here, I don't think we've covered this case either in our other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @bentsku 🙏🚀🙂 So I had already checked this case before writing the logic above; if we don't specify the value in this case it takes default False
value, which was covered in the above logic. Let me even write a test case for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bentsku - I have pushed the branch directly to localstack/localstack
repo: https://github.com/localstack/localstack/pull/7926
assert [ | ||
{ | ||
"id": validator_id, | ||
"name": name, | ||
"validateRequestBody": False, | ||
"validateRequestParameters": False, | ||
} | ||
] == result["items"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can delete this test, I believe your tests are covering much more ground than this one. Our goal would be to basically progressively delete those in favour on the new ones.
response = apigateway_client.get_request_validator( | ||
restApiId=api_id, requestValidatorId=validator_id | ||
) | ||
snapshot.match("get-request-validators", response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add this to test_create_request_validator
, as it is basically the same test extended with only one operation? Same for test_get_request_validators
.
I feel like we could condense some of the tests with the flow:
- create a validator
- get the validator
- get all validators
- delete the validator
- try getting the deleted validator
- get all validators
This would look a lot liketest_delete_request_validator
, which cover the same ground astest_create_request_validator
andtest_get_request_validators
.
With snapshot, we can take advantage of the fact that we can setup the resource one and follow its lifecycle.
We have good examples of this flow in the new lambda tests (see here:)def test_function_lifecycle(
Otherwise, it's impeccable and I like how you structured the tests, and it's very clear, thanks a lot for tackling this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! sweet set of snapshot tests 🚀
@@ -1083,11 +1081,36 @@ def update_request_validator( | |||
f"Validator {request_validator_id} for API Gateway {rest_api_id} not found" | |||
) | |||
|
|||
patched_validator = apply_json_patch_safe(validator, patch_operations) | |||
rest_api_container.validators[request_validator_id] = patched_validator | |||
for operation in patch_operations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: what if we instead of operation
use patch_operation
and after instead of operation_performed
we can use operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @calvernaz for the review 🚀🙏🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Awesome, thank you for addressing the comments and making the integration tests run! Good to merge 😄
For
RequestValidator
API in apigateway :test_request_validator