Skip to content

Commit

Permalink
combine toThrow unit tests into test loop
Browse files Browse the repository at this point in the history
  • Loading branch information
epoctic committed Aug 13, 2024
1 parent 5f89799 commit c47961e
Showing 1 changed file with 13 additions and 68 deletions.
81 changes: 13 additions & 68 deletions packages/aws-cdk-lib/aws-rds/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4411,86 +4411,31 @@ describe('cluster', () => {
Template.fromStack(stack).hasResourceProperties('AWS::RDS::DBCluster', {
ManageMasterUserPassword: true,
});

});

test('throw error for setting `manageMasterUserPassword` to true while `credentials` props excludeCharacters is defined', () => {
// Given
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');

// WHEN
expect(() => {
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_16_1 }),
manageMasterUserPassword: true,
credentials: { username: 'test', excludeCharacters: '1234' },
vpc,
writer: ClusterInstance.serverlessV2('writer'),
});

// THEN
}).toThrow('Only the `username` and `encryptionKey` credentials properties may be used when `manageMasterUserPassword` is true');
});

test('throw error for setting `manageMasterUserPassword` to true while `credentials` prop secret is defined', () => {
// Given
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');
const secret = new sm.Secret(stack, 'secret');

// WHEN
expect(() => {
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_16_1 }),
manageMasterUserPassword: true,
credentials: { secret: secret },
vpc,
writer: ClusterInstance.serverlessV2('writer'),
});

// THEN
}).toThrow('Only the `username` and `encryptionKey` credentials properties may be used when `manageMasterUserPassword` is true');
});

test('throw error for setting `manageMasterUserPassword` to true while `credentials` prop password is defined', () => {
// Given
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');
const secret = new sm.Secret(stack, 'secret');

// count allows for generation of unique identifiers each test run
let count = 0;
const stack = testStack();
test.each([
['excludeCharacters', { excludeCharacters: '1234' }],
['replicaRegions', { username: 'test', replicaRegions: ['us-east-1', 'us-west-2'] }],
['secret', { secret: new sm.Secret(stack, 'secret') }],
['Credentials', Credentials.fromSecret(new sm.Secret(stack, 'secret1'))],
])('throw error for setting `manageMasterUserPassword` to true while `credentials.%s` is defined', (_, credentials) => {
// WHEN
expect(() => {
new DatabaseCluster(stack, 'Database', {
new DatabaseCluster(stack, `Database${count}`, {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_16_1 }),
manageMasterUserPassword: true,
credentials: { username: 'test', replicaRegions: ['us-east-1', 'us-west-2'] },
vpc,
credentials: credentials,
vpc: new ec2.Vpc(stack, `VPC${count}`),
writer: ClusterInstance.serverlessV2('writer'),
});

// THEN
}).toThrow('Only the `username` and `encryptionKey` credentials properties may be used when `manageMasterUserPassword` is true');
});

test('throw error for setting `manageMasterUserPassword` to true while `credentials` is passed a Credentials object', () => {
// Given
const stack = testStack();
const vpc = new ec2.Vpc(stack, 'VPC');
const secret = new sm.Secret(stack, 'secret');

// WHEN
expect(() => {
new DatabaseCluster(stack, 'Database', {
engine: DatabaseClusterEngine.auroraPostgres({ version: AuroraPostgresEngineVersion.VER_16_1 }),
manageMasterUserPassword: true,
credentials: Credentials.fromSecret(secret),
vpc,
writer: ClusterInstance.serverlessV2('writer'),
});

// THEN
}).toThrow('Only the `username` and `encryptionKey` credentials properties may be used when `manageMasterUserPassword` is true');
count = count + 1;
});
});
});
Expand Down

0 comments on commit c47961e

Please sign in to comment.