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

refactor: Pull code to compute location into one function #1094

Merged

Conversation

danieljbruce
Copy link
Contributor

This pull request is dependent on #1093. After that PR and its predecessor are merged this one will just be a PR where we pull repeated functionality from two functions into a single utility function.

@danieljbruce danieljbruce requested review from a team as code owners June 1, 2022 21:03
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigtable Issues related to the googleapis/nodejs-bigtable API. labels Jun 1, 2022
@danieljbruce danieljbruce added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jun 1, 2022
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Jun 20, 2022
@danieljbruce danieljbruce added owlbot:run Add this label to trigger the Owlbot post processor. and removed do not merge Indicates a pull request not ready for merge, due to either quality or timing. labels Jun 21, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jun 21, 2022
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

If I understand correctly, this is a cleanup and refactor of existing behaviour, vs., a new feature?

I would title the PR in this case:

refactor: pull code to compute location into one function.


I like this cleanup 🥳 , but left a couple thoughts.

@@ -493,7 +493,10 @@ describe('Bigtable', () => {
});

it('should respect the clusters option', done => {
const fakeLocation = 'a/b/c/d';
const fakeLocation = Cluster.getLocation_(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that tests had to be updated, since it looks like this is just a refactor. Does the value of fakeLocation actually matter?

It may be better leave the existing tests as is, since it makes it more clear that this is simply a refactor.

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, fakeLocation must be changed in this test and the reason is that we mock out getLocation_ in fake cluster, but now getLocation_ is called in a ClusterUtils objects which uses the real cluster. What should we do? We could do one of the following:

  1. Change the test as I have done. OR
  2. Move this functionality into a private method of cluster instead so that the test does not need to be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like we decided just to get rid of the mocks that weren't being used.

@@ -85,6 +91,21 @@ export class ClusterUtils {
return updateMask;
}

static getClusterBaseConfigWithFullLocation(
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 we should try to add a test that specifically asserts against this expected behaviour:

it('populates full location path if location parameter provided')

What format is it expected that metadata.location is in? Is this value provided by a user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean add a test that calls getClusterBaseConfigWithFullLocation and then compares the output against a predetermined value?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would be tempted to add a test for the user behavior that would cause these different code paths to be hit.

One test for location being undefined, one test for location being set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test for location is here and I added an assertion:

https://github.com/googleapis/nodejs-bigtable/blob/release-v4.0.0/test/instance.ts#L338

We can't add a test for an undefined location because the interface requires location to be defined. I believe that if location is not provided then the server will throw an error.

export interface BasicClusterConfig {
  encryption?: google.bigtable.admin.v2.Cluster.IEncryptionConfig;
  key?: string;
  location: string;
  nodes?: number;
  storage?: string;
  minServeNodes?: number;
  maxServeNodes?: number;
  cpuUtilizationPercent?: number;
}

Keep in mind that a lot of the autogenerated tests from earlier make sure these refactors don't change functionality: https://github.com/googleapis/nodejs-bigtable/pull/1092/files#diff-9db6b3eefb5be3d2bc20f1be7f6d14141dbc06e562bd45daabd86b2f86bf3848R40 for example

We could change the interface of the user facing functions to make location optional and test for the error, but then we are expanding the API surface.

@danieljbruce danieljbruce changed the title feat: Pull code to compute location into one function refactor: Pull code to compute location into one function Jul 11, 2022
@danieljbruce danieljbruce added owlbot:run Add this label to trigger the Owlbot post processor. labels Jul 14, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 14, 2022
@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 18, 2022
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 18, 2022
@danieljbruce danieljbruce merged commit 81ea5f7 into googleapis:main Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/nodejs-bigtable API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants