Skip to content

Commit

Permalink
optimize logic / tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jumic committed Dec 14, 2021
1 parent 9c0e26d commit cb88532
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-rds/lib/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData
performanceInsightsRetentionPeriod: enablePerformanceInsights
? (props.performanceInsightRetention || PerformanceInsightRetention.DEFAULT)
: undefined,
port: props.port ? Tokenization.stringifyNumber(props.port) : undefined,
port: props.port !== undefined ? Tokenization.stringifyNumber(props.port) : undefined,
preferredBackupWindow: props.preferredBackupWindow,
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
processorFeatures: props.processorFeatures && renderProcessorFeatures(props.processorFeatures),
Expand Down
13 changes: 9 additions & 4 deletions packages/@aws-cdk/aws-rds/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ describe('instance', () => {
});
});

test('instance with port', () => {
test('instance with port provided as a number', () => {
// WHEN
new rds.DatabaseInstance(stack, 'Database', {
engine: rds.DatabaseInstanceEngine.MYSQL,
Expand All @@ -1646,19 +1646,24 @@ describe('instance', () => {
});
});

test('instance with port from token', () => {
test('instance with port provided as a CloudFormation parameter', () => {
// GIVEN
const port = new cdk.CfnParameter(stack, 'Port', {
type: 'Number',
}).valueAsNumber;

// WHEN
new rds.DatabaseInstance(stack, 'Database', {
engine: rds.DatabaseInstanceEngine.MYSQL,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
vpc,
port: cdk.Token.asNumber({ Ref: 'port' }),
port,
});

// THEN
expect(stack).toHaveResourceLike('AWS::RDS::DBInstance', {
Port: {
Ref: 'port',
Ref: 'Port',
},
});
});
Expand Down

0 comments on commit cb88532

Please sign in to comment.