Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class AuroraClusterInstance extends Resource implements IAuroraClusterInstance {
// Enhanced CDK Analytics Telemetry
addConstructMetadata(this, props);
this.tier = props.promotionTier ?? 2;
if (this.tier > 15) {
if (this.tier < 0 || this.tier > 15) {
throw new ValidationError(lit`PromotionTier`, 'promotionTier must be between 0-15', this);
}

Expand Down
24 changes: 24 additions & 0 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ describe('cluster new api', () => {
}).toThrow(/Provide either vpcSubnets or instanceProps.vpcSubnets, but not both/);
});

test.each([
[-1, /promotionTier must be between 0-15/],
[16, /promotionTier must be between 0-15/],
])('when promotionTier is %s', (promotionTier, errorMessage) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think errorMessage variable is not needed.

Suggested change
[-1, /promotionTier must be between 0-15/],
[16, /promotionTier must be between 0-15/],
])('when promotionTier is %s', (promotionTier, errorMessage) => {
-1, 16,
])('when promotionTier is %s', (promotionTier) => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I simplified the test by inlining the error message
and removing the unnecessary variable.

// GIVEN
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

expect(() => {
// WHEN
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.AURORA_MYSQL,
vpc,
writer: ClusterInstance.provisioned('writer'),
readers: [
ClusterInstance.provisioned('reader', {
promotionTier,
}),
],
});
// THEN
}).toThrow(errorMessage);
});

test.each([
[0.5, 300, /serverlessV2MaxCapacity must be >= 1 & <= 256/],
[0.5, 0, /serverlessV2MaxCapacity must be >= 1 & <= 256/],
Expand Down
Loading