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

Test httpRequestTests against actual Services #1708

Merged
merged 18 commits into from
Sep 9, 2022

Conversation

weihanglo
Copy link
Contributor

@weihanglo weihanglo commented Sep 5, 2022

Motivation and Context

#1212

Description

Before this PR, we constructs Request manually to test against @httpRequestTests of protocol compliances tests. After this PR, we construct a tower service and turn it into a Router.

That makes our test cases

  • exercise against a larger surface from routing to parameter validation.
  • avoids calling non-public method to exercise tests
  • test against HTTP method field

The implementation is quite simple. We add a helper module renderTestHelper which contains fn validate_request(…) sharing the logic of building a Router and exercise against each @httpRequestTests. We then put the assertion logic inside each operation handler. Some type coercions are needed inside fn create_operation_registry_builder(…) since we want a builder with blanket operations at first, and then set the actual operation handler for each test case.

Testing

Run ./gradlew codegen-server-test:test and see if all protocol tests are passed.

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions

This comment was marked as outdated.

@weihanglo weihanglo marked this pull request as ready for review September 5, 2022 18:20
@weihanglo weihanglo requested review from a team, crisidev and david-perez as code owners September 5, 2022 18:20
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

weihanglo and others added 12 commits September 8, 2022 00:09
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
Co-authored-by: david-perez <d@vidp.dev>
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
Signed-off-by: Weihang Lo <weihanglo@users.noreply.github.com>
@weihanglo weihanglo force-pushed the weihanglo/protocol-test-enhancement branch from 3ed0ad4 to 4212818 Compare September 8, 2022 00:09
@github-actions

This comment was marked as outdated.

@weihanglo
Copy link
Contributor Author

Most of the issues have been resolved. I marked minor refactoring comments as resolve and left other major issues unresolved. Thank you for your review, @david-perez!

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

Missing `X-Amz-Target` in response header
@github-actions

This comment was marked as outdated.

@github-actions
Copy link

github-actions bot commented Sep 9, 2022

A new generated diff is ready to view.

A new doc preview is ready to view.

val variant = data.members.iterator().next()
val memberName = variant.key.value

val variant = if (ctx.defaultsForRequiredFields && data.members.isEmpty()) {
Copy link
Contributor

@Velfi Velfi Sep 9, 2022

Choose a reason for hiding this comment

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

It'd be nice to destructure here, maybe something like this?

Suggested change
val variant = if (ctx.defaultsForRequiredFields && data.members.isEmpty()) {
val (memberName, memberDefaultValue) = if (ctx.defaultsForRequiredFields && data.members.isEmpty()) {

/**
* Returns a default value for a shape.
*
* Warning: this method does not take into account any constraint traits attached to the shape.
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice if these docs could include some examples of what this function does. You could take one of your tests and convert it.

Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

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

Client changes look good to me!

)

companion object {
fun defaultContext() = Ctx(lowercaseMapKeys = false, streaming = false, builder = false, defaultsForRequiredFields = false)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is fine, but it's a lot more flexible if you just set the defaults using default args directly on Ctx, since then you can override one of the defaults easily. For example, if you only wanted to override streaming: Ctx(streaming = true).

@weihanglo
Copy link
Contributor Author

Since this PR somehow blocks #1693 I'll merge it as is and do some follow-ups. Thank you all for the reviews!

@weihanglo weihanglo enabled auto-merge (squash) September 9, 2022 18:21
@github-actions

This comment was marked as outdated.

@github-actions
Copy link

github-actions bot commented Sep 9, 2022

A new generated diff is ready to view.

A new doc preview is ready to view.

@weihanglo weihanglo merged commit f27aa54 into main Sep 9, 2022
@weihanglo weihanglo deleted the weihanglo/protocol-test-enhancement branch September 9, 2022 20:07
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.

5 participants