-
Notifications
You must be signed in to change notification settings - Fork 2k
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: compute reservation create shared #3832
Conversation
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
9967e39
to
c9810b2
Compare
c903144
to
58e15ae
Compare
Please review #3868 first |
5471bb3
to
993617b
Compare
* limitations under the License. | ||
*/ | ||
|
||
/* eslint-disable no-dupe-keys */ |
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.
Reason for: /* eslint-disable no-dupe-keys */
According to the documentation: https://cloud.google.com/compute/docs/instances/reservations-modify#modifying-consumer-projects-shared-reservation. When we want to update consumer projects, we must define paths field for each consumer, e.g:
await reservationsClient.update({
project: projectId,
reservation: reservationName,
paths: 'shareSettings.projectMap.consumerId1',
paths: 'shareSettings.projectMap.consumerId2'
zone,
reservationResource: {
name: reservationName,
shareSettings: {
projectMap: {
consumerId1: {
projectId: 'consumerId1',
},
consumerId2: {
projectId: 'consumerId2',
},
},
},
},
});
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.
Really nice use of mocks, but overkill for a sample. Please simplify, per the comment I left. Thanks!
|
||
module.exports = main; | ||
|
||
// TODO(developer): Uncomment below lines before running the sample. |
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.
Hi @gryczj. My comment here will apply to both modules and to the test. What really are we looking for to know if the sample did what it was intended? We are not unit testing production APIs, we simply expect that our call to an API will have the intended result. What is that? A resource ID? Not returning a failed status code or catching an exception, etc? If you were a developer using this API in production code, what would you expect -- that's the check you could demonstrate right here. The unit test probably doesn't really need mocks and all the extra complexity; isn't it enough, really, if main doesn't throw (the process doesn't exit with a non-zero exit code)? Our samples shouldn't themselves be APIs, so no need to export anything out of this module.
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 just want to add your PRs have been great! To clarify here, the goal is that a sample should fully encapsulate the demonstration of what a developer needs to know to use our APIs successfully in their own production code. How is the API intended to be used? Our tests don't need to confirm that APIs work as expected, only that the sample works (we don't want broken samples in our docs for an unexpected reason, but we do expect that service teams have already exhaustively tested their services). Hope this helps!
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.
@subfuzion thank you for your comments and review :) I introduced mocks here because to create shared reservation special permission are required and also another project, that we want to use as consumer and share this reservation with. I can test this sample locally with my credentials, but I have no knowledge about our test environment and projects, which I can use here as an example in tests and this sample will throw errors.
I understand your point. All new changes in the implementation were made to allow me to use mocks and fake clients in tests and on the other hand allow user to use real clients if they want to.
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.
@subfuzion As @gryczj wrote, the shared reservation sample would require a separate project, with a change to organization policy to allow this project to share the reservation with other projects.
I made an "executive" call for the team that writes those samples for Python, Java, Go and Node to use mocks for those samples as a kind of an exception to the rule.
My arguments:
- We don't really do tests that span multiple projects.
- It'd be very easy to forget about this additional project and in a year or two we'd have to rediscover the whole thing.
- I know that Python has separate projects for every version of the language - having tests that span multiple projects that require org policy updates would make it harder to start up a new project for new version.
We acknowledge the value of proper testing and that's why mocks were picked as a middle ground between skipping tests for those samples and writing fully functional tests that would make use of multiple projects.
Let me know if I managed to convince you or not :)
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 added context. I still don't see the need to mock console or treat the sample like its library code and have it export a function for testing, and my points about overall test simplification still remain. I'd like to surface this up to the rest of our team for discussion, so can you please address the points I've raised specifically?
Also, overall test flakiness still seems to be a problem, such as the compute hyperdisk failures for #3834 (which I merged so we can consolidate efforts on a single PR).
Thanks!
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.
Please feel free to ping me directly on internal chat: tonypujals@
Overriding failed test because tests need to be fixed in PR #3832
23bf1b4
to
bce6e24
Compare
9c74595
to
35e5cf8
Compare
7c4d943
to
55714fa
Compare
55714fa
to
a5a85e1
Compare
a5a85e1
to
328d42d
Compare
To keep commit history clean I moved changes to new PR: #3894 |
Description
Fixes #
Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.
Checklist
npm test
(see Testing)npm run lint
(see Style)GoogleCloudPlatform/nodejs-docs-samples
. Not a fork.