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

Modify and Merge protocol test request unit tests codegen logic #445

Closed
wants to merge 5 commits into from

Conversation

wty-Bryant
Copy link
Contributor

Modify and Merge protocol test request unit tests codegen logic to isolate cases from local server and instead capture and check request directly via middleware

@wty-Bryant wty-Bryant requested review from a team as code owners August 11, 2023 21:04
@@ -282,7 +274,8 @@ protected void generateTestServer(
String name,
Consumer<GoWriter> handler
) {
super.generateTestServer(writer, name, handler);
// We aren't using a test server, but we do need a URL to set.
writer.write("serverURL := \"http://localhost:8888/\"");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just remove this entire generateTestServer method? Is its code needed at all anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we do that we have to remove it from super class HttpProtocolUnitTestGenerator and simply provide this fake url to request and response generator separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also we need the test cases' host info in some host test cases, I prefer to keep it now in case of breaking changes.

const captureRequestID = "CaptureProtocolTestRequest"

// AddCaptureRequestMiddleware captures serialized http request during protocol test for check
func AddCaptureRequestMiddleware(stack *middleware.Stack, req *http.Request) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Do we have to expose this in the public API?

If I understand correctly, the generated protocol tests in the SDK repo will have to see it to use it, but I think I'd rather we just generate it as unexported code in the protocol test instead of having it be exported in smithy-go just to be used for testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that if/when we go that route you can just drop the unit test. The protocol tests needing to pass based on it are assertion enough imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively we can put it somewhere under private/ like we've done in a few other places - to have it usable by the SDK, but to signal that we don't want other people doing so.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer alternative method cause the it prevent smithy go codegen using some sdk dependency of middleware. I will create a new private/ directory under smithy-go repo and move the middleware there.

@@ -250,20 +241,21 @@ protected void generateTestAssertions(GoWriter writer) {
writeAssertNil(writer, "err");
writeAssertNotNil(writer, "result");

writeAssertScalarEqual(writer, "c.ExpectMethod", "actualReq.Method", "method");
writeAssertScalarEqual(writer, "c.ExpectURIPath", "actualReq.URL.RawPath", "path");
writeAssertScalarEqual(writer, "c.ExpectMethod", "capturedReq.Method", "method");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is totally fine but you might have been able to get away with less changes by just connecting your new middleware to the originally declared actualReq request.

@wty-Bryant wty-Bryant closed this Aug 16, 2023
@wty-Bryant wty-Bryant deleted the feat-protocol-test branch August 16, 2023 21: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.

2 participants