fix(docdb): make most attributes of DatabaseClusterAttributes optional#19625
Conversation
|
Title does not follow the guidelines of Conventional Commits. Please adjust title before merge. |
0f0fc84 to
1b9ee78
Compare
| /** | ||
| * Represents an imported database cluster. | ||
| */ | ||
| class ImportedDatabaseCluster extends DatabaseClusterBase implements IDatabaseCluster { |
There was a problem hiding this comment.
Out of curiosity - why did you move this class from where it was defined?
Let's maybe leave it where it is - this way, the diff will be significantly smaller?
There was a problem hiding this comment.
Thanks all for the lighting fast response!
I have made changes based on the following code.
aws-cdk/packages/@aws-cdk/aws-rds/lib/cluster.ts
Lines 427 to 487 in 4071d9b
but I agree with your suggestion. So I left it as is and made fix.
| test('minimal imported cluster throws on accessing attributes for unprovided parameters', () => { | ||
| const stack = testStack(); | ||
|
|
||
| const cluster = DatabaseCluster.fromDatabaseClusterAttributes(stack, 'Database', { | ||
| clusterIdentifier: 'identifier', | ||
| }); | ||
|
|
||
| expect(() => cluster.clusterEndpoint).toThrow(/Cannot access `clusterEndpoint` of an imported cluster/); | ||
| expect(() => cluster.clusterReadEndpoint).toThrow(/Cannot access `clusterReadEndpoint` of an imported cluster/); | ||
| expect(() => cluster.instanceIdentifiers).toThrow(/Cannot access `instanceIdentifiers` of an imported cluster/); | ||
| expect(() => cluster.instanceEndpoints).toThrow(/Cannot access `instanceEndpoints` of an imported cluster/); | ||
| expect(() => cluster.securityGroupId).toThrow(/Cannot access `securityGroupId` of an imported cluster/); | ||
| }); |
There was a problem hiding this comment.
Let's maybe merge these 2 into one test?
1b9ee78 to
981e56b
Compare
| private readonly _instanceEndpoints?: Endpoint[]; | ||
| private readonly _securityGroupId?: string; | ||
|
|
||
| constructor(_scope: Construct, _id: string, _attrs: DatabaseClusterAttributes) { |
There was a problem hiding this comment.
Do we need this constructor? Can't we just assign the fields like _clusterEndpoint and _clusterReadEndpoint directly, like we do for clusterIdentifier and defaultPort?
| this._clusterEndpoint = (_attrs.clusterEndpointAddress && _attrs.port) ? new Endpoint(_attrs.clusterEndpointAddress, _attrs.port) : undefined; | ||
| this._clusterReadEndpoint = (_attrs.readerEndpointAddress && _attrs.port) | ||
| ? new Endpoint(_attrs.readerEndpointAddress, _attrs.port) | ||
| : undefined; | ||
| this._instanceIdentifiers = _attrs.instanceIdentifiers; | ||
| this._instanceEndpoints = (_attrs.instanceEndpointAddresses && _attrs.port) |
There was a problem hiding this comment.
We don't need the parenthesis in the ternary operator, let's get rid of them.
| public static fromDatabaseClusterAttributes(scope: Construct, id: string, attrs: DatabaseClusterAttributes): IDatabaseCluster { | ||
| class Import extends DatabaseClusterBase implements IDatabaseCluster { | ||
| public readonly defaultPort = ec2.Port.tcp(attrs.port); | ||
| public readonly clusterIdentifier = attrs.clusterIdentifier; |
There was a problem hiding this comment.
Can we keep the fields in the same order they are now? This way, the diff will be easier to to read.
| class Import extends DatabaseClusterBase implements IDatabaseCluster { | ||
| public readonly defaultPort = ec2.Port.tcp(attrs.port); | ||
| public readonly clusterIdentifier = attrs.clusterIdentifier; | ||
| public readonly defaultPort = attrs.port ? ec2.Port.tcp(attrs.port) : undefined; |
There was a problem hiding this comment.
Remember that 0 is falsy in JavaScript/TypeScript. You probably want to compare against undefined here.
| public readonly defaultPort = attrs.port ? ec2.Port.tcp(attrs.port) : undefined; | ||
| public readonly connections = new ec2.Connections({ | ||
| securityGroups: [attrs.securityGroup], | ||
| securityGroups: !!attrs.securityGroup ? [attrs.securityGroup] : undefined, |
There was a problem hiding this comment.
Why the double !! here, all of a sudden? Removing it will not change this code.
| return this._instanceEndpoints; | ||
| } | ||
|
|
||
| public get securityGroupId() { |
There was a problem hiding this comment.
Can you specify the return types for all of these getters?
8157fe3 to
1ace74d
Compare
| public readonly clusterReadEndpoint = new Endpoint(attrs.readerEndpointAddress, attrs.port); | ||
| public readonly instanceEndpoints = attrs.instanceEndpointAddresses.map(a => new Endpoint(a, attrs.port)); | ||
| public readonly securityGroupId = attrs.securityGroup.securityGroupId; | ||
| private readonly _instanceIdentifiers?= attrs.instanceIdentifiers; |
There was a problem hiding this comment.
Why the ?=? I think this should just be a =. Also, missing space:
| private readonly _instanceIdentifiers?= attrs.instanceIdentifiers; | |
| private readonly _instanceIdentifiers = attrs.instanceIdentifiers; |
Same comment in the other fields added in the PR.
There was a problem hiding this comment.
Thank you for suggestion! I fixed the use of optional properties.
Co-authored-by: sandship <sandship.blancard@gmail.com> Co-authored-by: yoshitaka KOITABASHI <Yoshiitaka@users.noreply.github.com>
directory assign fields add return types in getter
99f66fc to
dcccdc2
Compare
|
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
aws#19625) Fixes aws#14492 - Test Result ``` ❯ yarn test yarn run v1.22.17 $ cdk-test PASS test/endpoint.test.js (17.557 s) PASS test/parameter-group.test.js (17.601 s) PASS test/instance.test.js (18.16 s) PASS test/cluster.test.js (19.233 s) =============================== Coverage summary =============================== Statements : 98.76% ( 160/162 ) Branches : 99.02% ( 102/103 ) Functions : 100% ( 27/27 ) Lines : 98.75% ( 158/160 ) ================================================================================ Test Suites: 4 passed, 4 total Tests: 51 passed, 51 total Snapshots: 0 total Time: 19.946 s Ran all test suites. Verifying integ.cluster-rotation.lit.js against integ.cluster-rotation.lit.expected.json ... OK. Verifying integ.cluster.js against integ.cluster.expected.json ... OK. Tests successful. Total time (26.2s) | /Users/yoshitaka.koitabashi/Desktop/OSS/tmp/aws-cdk/node_modules/jest/bin/jest.js (23.8s) | cdk-integ-assert (2.4s) ✨ Done in 26.72s. ``` ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/master/INTEGRATION_TESTS.md)? * [ ] Did you use `cdk-integ` to deploy the infrastructure and generate the snapshot (i.e. `cdk-integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Fixes #14492
All Submissions:
Adding new Unconventional Dependencies:
New Features
cdk-integto deploy the infrastructure and generate the snapshot (i.e.cdk-integwithout--dry-run)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license