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

feat(go): CTS implementation for go client #1509

Merged
merged 12 commits into from
May 9, 2023

Conversation

mehmetaligok
Copy link
Contributor

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-661

The CTS suite for go client implemented.

Changes included:

  • Test templates created for the generation.
    • When creating tests, json unmarshaller is used to parse requests. Initially, I tried to create the request the regular way but couldn't do it properly. The main issues were mostly about different "oneof" types and some very detailed requests. Unfortunately, generating these in Go with the mustache is not easy since mustache is all about "Logic-less" templates.
    • Maybe we can revisit this later. We may need some improvements for CTS in general because creating CTS stuff is hard to manage and not straightforward.
  • extras field added to test json specs.
    • It is added for skipForGo prop. It was needed for three specific test cases. The client was working okay but the test unmarshalling was not working properly because of the payload. No need to block this improvement for this.
    • These extras can be also used for some other cases in the future because the only request may not be enough for all the language generations.
  • Added some improvements for client generation.
    • UnmarshalJSON implemented for request struct to handle json parsing for the direct request.
    • "OneOf" model unmarshaling updated to add an extra validation.

🧪 Test

The test should run with CI.

@mehmetaligok mehmetaligok added the Go label May 2, 2023
@mehmetaligok mehmetaligok self-assigned this May 2, 2023
@netlify
Copy link

netlify bot commented May 2, 2023

Deploy Preview for api-clients-automation ready!

Name Link
🔨 Latest commit de5ce27
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/6454ceccd117a6000924c41c
😎 Deploy Preview https://deploy-preview-1509--api-clients-automation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@algolia-bot
Copy link
Collaborator

algolia-bot commented May 2, 2023

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.
You can still access the code generated on main via this commit.

@mehmetaligok mehmetaligok marked this pull request as ready for review May 2, 2023 11:47
@mehmetaligok mehmetaligok requested a review from a team as a code owner May 2, 2023 11:47
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

Nice ! But it looks like the tests are not generated on the CI, I think it's an artifact issue, can you try to tweak .github/actions/restore-artifacts/action.yml file to include cts ?

@@ -22,6 +22,17 @@ async function runCtsOne(language: string): Promise<void> {
);
break;
}
case 'go':
if (DOCKER) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think you need the distinction for docker, /usr/local/go/bin/go is already in the PATH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, it is in the PATH but somehow it is not working with js runtime. I can run with just go from the container but when I used it with the run function it is not working.

I couldn't quite figure out the reason last time. So I already opened a separate ticket to resolve this if possible.

@@ -55,6 +55,9 @@
]
}
}
},
"extras": {
"skipForGo": true
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you have an idea why the payload doesn't work here ? is it because of oneOf ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes mainly because of "oneof". The contents of "oneof"s are very similar for this request. Since I used the json unmarshalling, the expected request body is not matching completely. It is unmarshalling it to a different "oneof" because it is matching with more than one statement.

When I tried to create the request with a constructor it worked without an issue, I couldn't make it work for the tests. I have opened another ticket to improve some of the CTS workflow for development. Maybe that can ease the development so we can take a look at this later on.

@mehmetaligok
Copy link
Contributor Author

Nice ! But it looks like the tests are not generated on the CI, I think it's an artifact issue, can you try to tweak .github/actions/restore-artifacts/action.yml file to include cts ?

@millotp Oh, I tried on local but I haven't noticed the test code does not exist on the generated branch. It is my bad. Let me take a look and update here. Thanks for the heads up.

@mehmetaligok
Copy link
Contributor Author

@millotp push problem for the generated branch should be resolved. It is ready to be reviewed again. I also do some extra tests for negative and positive CI scenarios to ensure the cts run is working properly for the CI. I believe everything is in place right now.

@mehmetaligok mehmetaligok requested a review from millotp May 3, 2023 11:02
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

looks great GG ! Huge PR

}

{{#blocksRequests}}
func Test{{#lambda.titlecase}}{{clientPrefix}}{{/lambda.titlecase}}_{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know the execution time is already very fast, but can you add t.Parallel() here and in the for loop pls ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since currently, we are using only an echo requester adding t.Parallel() is bringing flakiness to the tests. Some tests start randomly failing.

We may need to add some complexity to test cases to handle this, I guess we can skip this at this phase.

Copy link
Collaborator

Choose a reason for hiding this comment

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

no worries the test runs very fast already


{{#request.body}}
ja := jsonassert.New(t)
ja.Assertf(*echo.body, `{{{request.body}}}`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible to assert the query params too ? if they are returned from the echo requester

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 noticing. While adding query param and header assertions I noticed a few problems regarding the custom requests. They are also fixed with 402d69a and all ready to be reviewed.

aallam
aallam previously approved these changes May 4, 2023
@aallam
Copy link
Member

aallam commented May 4, 2023

Nice work! and as you mentioned, I am for revisiting the CTS specs for easier tests generation! Well done! 🚀

@mehmetaligok mehmetaligok requested a review from aallam May 4, 2023 14:53
…plementation

# Conflicts:
#	generators/src/main/java/com/algolia/codegen/cts/manager/CTSManagerFactory.java
#	scripts/cts/runCts.ts
{{#request.queryParameters}}
queryParams := map[string]string{}
require.NoError(t, json.Unmarshal([]byte(`{{{.}}}`), &queryParams))
for k, v := range queryParams {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't remember what we do in other languages, but it might be worth to do a strict comparaison here, and check that the number of query params is the same in queryParams and in echo.query

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, I miss this before merging. But I noted this to check out.

Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

looks amazing ! somehow kotlin shows up in the generation this time @aallam 🤔

@mehmetaligok mehmetaligok merged commit 4fb9def into main May 9, 2023
@mehmetaligok mehmetaligok deleted the feat/go-client-cts-implementation branch May 9, 2023 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants