8000 Added test cases and fixed issues for RequestValidator apigateway by sannya-singal · Pull Request #7917 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 4 commits into from
Mar 22, 2023

Conversation

sannya-singal
Copy link
Contributor
@sannya-singal sannya-singal commented Mar 21, 2023

For RequestValidator API in apigateway :

  • Wrote create, list, delete, update, invalid operations, etc. test cases
  • Resolved issues for json patching, invalid messages, conflicts in responses, etc.
  • Fix existing test case- test_request_validator

Copy link
Contributor
@bentsku bentsku left a 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! 🎉

Comment on lines 1103 to 1107
if key in ["validateRequestParameters", "validateRequestBody"]:
if value.lower() == "true":
value = True
else:
value = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author
@sannya-singal sannya-singal Mar 22, 2023

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

Comment on lines 1029 to 1036
assert [
{
"id": validator_id,
"name": name,
"validateRequestBody": False,
"validateRequestParameters": False,
}
] == result["items"]
Copy link
Contributor

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.

Comment on lines 1563 to 1566
response = apigateway_client.get_request_validator(
restApiId=api_id, requestValidatorId=validator_id
)
snapshot.match("get-request-validators", response)
Copy link
Contributor

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 like test_delete_request_validator, which cover the same ground as test_create_request_validator and test_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!

Copy link
Contributor
@calvernaz calvernaz left a 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:
Copy link
Contributor

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

Copy link
Contributor Author

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 🚀🙏🙂

@sannya-singal sannya-singal temporarily deployed to localstack-ext-tests March 22, 2023 07:46 — with GitHub Actions Inactive
@github-actions
Copy link

LocalStack integration with Pro

       3 files  ±0         3 suites  ±0   1h 34m 17s ⏱️ - 13m 28s
1 843 tests +5  1 454 ✔️ +6  389 💤  - 1  0 ±0 
2 577 runs  +3  1 819 ✔️ +4  758 💤  - 1  0 ±0 

Results for commit 92676e7. ± Comparison against base commit 5f13258.

Copy link
Contributor
@bentsku bentsku left a 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 😄

@bentsku bentsku merged commit 805b4a5 into localstack:master Mar 22, 2023
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

Successfully merging this pull request may close these issues.

3 participants
0